Skip to content

Commit 73485e4

Browse files
committed
moved ShowTime from timer.h to settings.h
1 parent d2b2dfe commit 73485e4

10 files changed

Lines changed: 46 additions & 50 deletions

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ $(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathli
695695
frontend/frontend.o: frontend/frontend.cpp frontend/frontend.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/utils.h
696696
$(CXX) ${INCLUDE_FOR_FE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ frontend/frontend.cpp
697697

698-
cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/filelister.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h lib/xml.h
698+
cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/filelister.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/utils.h lib/xml.h
699699
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cmdlineparser.cpp
700700

701701
cli/cppcheckexecutor.o: cli/cppcheckexecutor.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/cppcheckexecutor.h cli/executor.h cli/processexecutor.h cli/sehwrapper.h cli/signalhandler.h cli/singleexecutor.h cli/threadexecutor.h externals/picojson/picojson.h lib/addoninfo.h lib/analyzerinfo.h lib/check.h lib/checkers.h lib/checkersreport.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/sarifreport.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h
@@ -776,7 +776,7 @@ test/testclangimport.o: test/testclangimport.cpp lib/addoninfo.h lib/check.h lib
776776
test/testclass.o: test/testclass.cpp lib/addoninfo.h lib/check.h lib/checkclass.h lib/checkers.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h test/fixture.h test/helpers.h
777777
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testclass.cpp
778778

779-
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h
779+
test/testcmdlineparser.o: test/testcmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/suppressions.h lib/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h test/redirect.h
780780
$(CXX) ${INCLUDE_FOR_TEST} ${CFLAGS_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testcmdlineparser.cpp
781781

782782
test/testcolor.o: test/testcolor.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/regex.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h

cli/cmdlineparser.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "settings.h"
3737
#include "standards.h"
3838
#include "suppressions.h"
39-
#include "timer.h"
4039
#include "utils.h"
4140

4241
#include "frontend.h"
@@ -1430,17 +1429,17 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
14301429
else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
14311430
const std::string showtimeMode = argv[i] + 11;
14321431
if (showtimeMode == "file")
1433-
mSettings.showtime = ShowTime::FILE;
1432+
mSettings.showtime = Settings::ShowTime::FILE;
14341433
else if (showtimeMode == "file-total")
1435-
mSettings.showtime = ShowTime::FILE_TOTAL;
1434+
mSettings.showtime = Settings::ShowTime::FILE_TOTAL;
14361435
else if (showtimeMode == "summary")
1437-
mSettings.showtime = ShowTime::SUMMARY;
1436+
mSettings.showtime = Settings::ShowTime::SUMMARY;
14381437
else if (showtimeMode == "top5_file")
1439-
mSettings.showtime = ShowTime::TOP5_FILE;
1438+
mSettings.showtime = Settings::ShowTime::TOP5_FILE;
14401439
else if (showtimeMode == "top5_summary")
1441-
mSettings.showtime = ShowTime::TOP5_SUMMARY;
1440+
mSettings.showtime = Settings::ShowTime::TOP5_SUMMARY;
14421441
else if (showtimeMode == "none")
1443-
mSettings.showtime = ShowTime::NONE;
1442+
mSettings.showtime = Settings::ShowTime::NONE;
14441443
else if (showtimeMode.empty()) {
14451444
mLogger.printError("no mode provided for --showtime");
14461445
return Result::Fail;

cli/cppcheckexecutor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
269269
}
270270

271271
std::unique_ptr<OneShotTimer> overallTimer;
272-
if (settings.showtime == ShowTime::SUMMARY || settings.showtime == ShowTime::TOP5_SUMMARY)
272+
if (settings.showtime == Settings::ShowTime::SUMMARY || settings.showtime == Settings::ShowTime::TOP5_SUMMARY)
273273
overallTimer.reset(new OneShotTimer("Overall time"));
274274

275275
settings.loadSummaries();
@@ -422,7 +422,7 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
422422
{
423423
StdLogger stdLogger(settings);
424424
std::unique_ptr<TimerResults> timerResults;
425-
if (settings.showtime != ShowTime::NONE)
425+
if (settings.showtime != Settings::ShowTime::NONE)
426426
timerResults.reset(new TimerResults);
427427

428428
if (settings.reportProgress >= 0)
@@ -468,9 +468,9 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
468468

469469
// TODO: show time *after* the whole program analysis
470470
if (timerResults) {
471-
if (settings.showtime == ShowTime::SUMMARY)
471+
if (settings.showtime == Settings::ShowTime::SUMMARY)
472472
timerResults->showResults();
473-
else if (settings.showtime == ShowTime::TOP5_SUMMARY)
473+
else if (settings.showtime == Settings::ShowTime::TOP5_SUMMARY)
474474
timerResults->showResults(5);
475475
}
476476

lib/cppcheck.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
924924
return mLogger->exitcode();
925925

926926
std::unique_ptr<OneShotTimer> checkTimeTimer;
927-
if (mSettings.showtime == ShowTime::FILE || mSettings.showtime == ShowTime::FILE_TOTAL || mSettings.showtime == ShowTime::TOP5_FILE)
927+
if (mSettings.showtime == Settings::ShowTime::FILE || mSettings.showtime == Settings::ShowTime::FILE_TOTAL || mSettings.showtime == Settings::ShowTime::TOP5_FILE)
928928
checkTimeTimer.reset(new OneShotTimer("Check time: " + file.spath()));
929929

930930
if (!mSettings.quiet) {
@@ -1180,7 +1180,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
11801180

11811181
Tokenizer tokenizer(std::move(tokenlist), mErrorLogger);
11821182
try {
1183-
if (mSettings.showtime != ShowTime::NONE)
1183+
if (mSettings.showtime != Settings::ShowTime::NONE)
11841184
tokenizer.setTimerResults(mTimerResults);
11851185
tokenizer.setDirectives(directives); // TODO: how to avoid repeated copies?
11861186

@@ -1295,9 +1295,9 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
12951295
mLogger->clear();
12961296

12971297
if (mTimerResults) {
1298-
if (mSettings.showtime == ShowTime::FILE)
1298+
if (mSettings.showtime == Settings::ShowTime::FILE)
12991299
mTimerResults->showResults();
1300-
else if (mSettings.showtime == ShowTime::TOP5_FILE)
1300+
else if (mSettings.showtime == Settings::ShowTime::TOP5_FILE)
13011301
mTimerResults->showResults(5);
13021302
}
13031303

lib/settings.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class Regex;
5353
#endif
5454

5555
struct Suppressions;
56-
enum class ShowTime : std::uint8_t;
5756
namespace ValueFlow {
5857
class Value;
5958
}
@@ -442,6 +441,15 @@ class CPPCHECKLIB WARN_UNUSED Settings {
442441
SimpleEnableGroup<Certainty> certainty;
443442
SimpleEnableGroup<Checks> checks;
444443

444+
enum class ShowTime : std::uint8_t {
445+
NONE,
446+
FILE,
447+
FILE_TOTAL,
448+
SUMMARY,
449+
TOP5_SUMMARY,
450+
TOP5_FILE
451+
};
452+
445453
/** @brief show timing information (--showtime=file|summary|top5) */
446454
ShowTime showtime{};
447455

lib/timer.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include <chrono>
2626
#include <cstddef>
27-
#include <cstdint>
2827
#include <limits>
2928
#include <map>
3029
#include <memory>
@@ -34,15 +33,6 @@
3433
#include <utility>
3534
#include <vector>
3635

37-
enum class ShowTime : std::uint8_t {
38-
NONE,
39-
FILE,
40-
FILE_TOTAL,
41-
SUMMARY,
42-
TOP5_SUMMARY,
43-
TOP5_FILE
44-
};
45-
4636
class CPPCHECKLIB TimerResultsIntf {
4737
public:
4838
virtual ~TimerResultsIntf() = default;

test/testcmdlineparser.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "settings.h"
3232
#include "standards.h"
3333
#include "suppressions.h"
34-
#include "timer.h"
3534
#include "utils.h"
3635

3736
#include <cstdio>
@@ -2193,21 +2192,21 @@ class TestCmdlineParser : public TestFixture {
21932192
REDIRECT;
21942193
const char * const argv[] = {"cppcheck", "--showtime=summary", "file.cpp"};
21952194
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2196-
ASSERT(settings->showtime == ShowTime::SUMMARY);
2195+
ASSERT_EQUALS_ENUM(Settings::ShowTime::SUMMARY, settings->showtime);
21972196
}
21982197

21992198
void showtimeFile() {
22002199
REDIRECT;
22012200
const char * const argv[] = {"cppcheck", "--showtime=file", "file.cpp"};
22022201
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2203-
ASSERT(settings->showtime == ShowTime::FILE);
2202+
ASSERT_EQUALS_ENUM(Settings::ShowTime::FILE, settings->showtime);
22042203
}
22052204

22062205
void showtimeFileTotal() {
22072206
REDIRECT;
22082207
const char * const argv[] = {"cppcheck", "--showtime=file-total", "file.cpp"};
22092208
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2210-
ASSERT(settings->showtime == ShowTime::FILE_TOTAL);
2209+
ASSERT_EQUALS_ENUM(Settings::ShowTime::FILE_TOTAL, settings->showtime);
22112210
}
22122211

22132212
void showtimeTop5() {
@@ -2221,21 +2220,21 @@ class TestCmdlineParser : public TestFixture {
22212220
REDIRECT;
22222221
const char * const argv[] = {"cppcheck", "--showtime=top5_file", "file.cpp"};
22232222
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2224-
ASSERT(settings->showtime == ShowTime::TOP5_FILE);
2223+
ASSERT_EQUALS_ENUM(Settings::ShowTime::TOP5_FILE, settings->showtime);
22252224
}
22262225

22272226
void showtimeTop5Summary() {
22282227
REDIRECT;
22292228
const char * const argv[] = {"cppcheck", "--showtime=top5_summary", "file.cpp"};
22302229
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2231-
ASSERT(settings->showtime == ShowTime::TOP5_SUMMARY);
2230+
ASSERT_EQUALS_ENUM(Settings::ShowTime::TOP5_SUMMARY, settings->showtime);
22322231
}
22332232

22342233
void showtimeNone() {
22352234
REDIRECT;
22362235
const char * const argv[] = {"cppcheck", "--showtime=none", "file.cpp"};
22372236
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2238-
ASSERT(settings->showtime == ShowTime::NONE);
2237+
ASSERT_EQUALS_ENUM(Settings::ShowTime::NONE, settings->showtime);
22392238
}
22402239

22412240
void showtimeEmpty() {

test/testprocessexecutor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TestProcessExecutorBase : public TestFixture {
6464
struct CheckOptions
6565
{
6666
bool quiet = true;
67-
ShowTime showtime = ShowTime::NONE;
67+
Settings::ShowTime showtime = Settings::ShowTime::NONE;
6868
const char* plistOutput = nullptr;
6969
std::vector<std::string> filesList;
7070
};
@@ -177,7 +177,7 @@ class TestProcessExecutorBase : public TestFixture {
177177
"void f()\n"
178178
"{\n"
179179
" (void)(*((int*)0));\n"
180-
"}", dinit(CheckOptions, $.showtime = ShowTime::SUMMARY));
180+
"}", dinit(CheckOptions, $.showtime = Settings::ShowTime::SUMMARY));
181181
// we are not interested in the results - so just consume them
182182
ignore_errout();
183183
}
@@ -246,7 +246,7 @@ class TestProcessExecutorBase : public TestFixture {
246246
check(2, 2, 0,
247247
"int main() {}",
248248
dinit(CheckOptions,
249-
$.showtime = ShowTime::TOP5_FILE));
249+
$.showtime = Settings::ShowTime::TOP5_FILE));
250250
const std::string output_s = GET_REDIRECT_OUTPUT;
251251
// for each file: top5 results + check time
252252
TODO_ASSERT_EQUALS(static_cast<long long>(5 + 1) * 2, 0, cppcheck::count_all_of(output_s, '\n'));
@@ -257,7 +257,7 @@ class TestProcessExecutorBase : public TestFixture {
257257
check(2, 2, 0,
258258
"int main() {}",
259259
dinit(CheckOptions,
260-
$.showtime = ShowTime::FILE));
260+
$.showtime = Settings::ShowTime::FILE));
261261
const std::string output_s = GET_REDIRECT_OUTPUT;
262262
TODO_ASSERT_EQUALS(2, 0, cppcheck::count_all_of(output_s, "Overall time:"));
263263
}
@@ -267,7 +267,7 @@ class TestProcessExecutorBase : public TestFixture {
267267
check(2, 2, 0,
268268
"int main() {}",
269269
dinit(CheckOptions,
270-
$.showtime = ShowTime::FILE_TOTAL));
270+
$.showtime = Settings::ShowTime::FILE_TOTAL));
271271
const std::string output_s = GET_REDIRECT_OUTPUT;
272272
TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_1.c: ") != std::string::npos);
273273
TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_2.c: ") != std::string::npos);

test/testsingleexecutor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class TestSingleExecutorBase : public TestFixture {
6161
struct CheckOptions
6262
{
6363
bool quiet = true;
64-
ShowTime showtime = ShowTime::NONE;
64+
Settings::ShowTime showtime = Settings::ShowTime::NONE;
6565
const char* plistOutput = nullptr;
6666
std::vector<std::string> filesList;
6767
};
@@ -165,7 +165,7 @@ class TestSingleExecutorBase : public TestFixture {
165165
"void f()\n"
166166
"{\n"
167167
" (void)(*((int*)0));\n"
168-
"}", dinit(CheckOptions, $.showtime = ShowTime::SUMMARY));
168+
"}", dinit(CheckOptions, $.showtime = Settings::ShowTime::SUMMARY));
169169
// we are not interested in the results - so just consume them
170170
ignore_errout();
171171
}
@@ -239,7 +239,7 @@ class TestSingleExecutorBase : public TestFixture {
239239
check(2, 0,
240240
"int main() {}",
241241
dinit(CheckOptions,
242-
$.showtime = ShowTime::TOP5_FILE));
242+
$.showtime = Settings::ShowTime::TOP5_FILE));
243243
const std::string output_s = GET_REDIRECT_OUTPUT;
244244
// for each file: top5 results + check time
245245
ASSERT_EQUALS((5 + 1) * 2LL, cppcheck::count_all_of(output_s, '\n'));
@@ -250,7 +250,7 @@ class TestSingleExecutorBase : public TestFixture {
250250
check(2, 0,
251251
"int main() {}",
252252
dinit(CheckOptions,
253-
$.showtime = ShowTime::FILE));
253+
$.showtime = Settings::ShowTime::FILE));
254254
const std::string output_s = GET_REDIRECT_OUTPUT;
255255
ASSERT_EQUALS(0, cppcheck::count_all_of(output_s, "Overall time:"));
256256
}
@@ -260,7 +260,7 @@ class TestSingleExecutorBase : public TestFixture {
260260
check(2, 0,
261261
"int main() {}",
262262
dinit(CheckOptions,
263-
$.showtime = ShowTime::FILE_TOTAL));
263+
$.showtime = Settings::ShowTime::FILE_TOTAL));
264264
const std::string output_s = GET_REDIRECT_OUTPUT;
265265
ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(1) + ".c: ") != std::string::npos);
266266
ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(2) + ".c: ") != std::string::npos);

test/testthreadexecutor.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class TestThreadExecutorBase : public TestFixture {
6464
struct CheckOptions
6565
{
6666
bool quiet = true;
67-
ShowTime showtime = ShowTime::NONE;
67+
Settings::ShowTime showtime = Settings::ShowTime::NONE;
6868
const char* plistOutput = nullptr;
6969
std::vector<std::string> filesList;
7070
};
@@ -178,7 +178,7 @@ class TestThreadExecutorBase : public TestFixture {
178178
"void f()\n"
179179
"{\n"
180180
" (void)(*((int*)0));\n"
181-
"}", dinit(CheckOptions, $.showtime = ShowTime::SUMMARY));
181+
"}", dinit(CheckOptions, $.showtime = Settings::ShowTime::SUMMARY));
182182
// we are not interested in the results - so just consume them
183183
ignore_errout();
184184
}
@@ -247,7 +247,7 @@ class TestThreadExecutorBase : public TestFixture {
247247
check(2, 2, 0,
248248
"int main() {}",
249249
dinit(CheckOptions,
250-
$.showtime = ShowTime::TOP5_FILE));
250+
$.showtime = Settings::ShowTime::TOP5_FILE));
251251
const std::string output_s = GET_REDIRECT_OUTPUT;
252252
// for each file: top5 results + check time
253253
ASSERT_EQUALS((5 + 1) * 2LL, cppcheck::count_all_of(output_s, '\n'));
@@ -258,7 +258,7 @@ class TestThreadExecutorBase : public TestFixture {
258258
check(2, 2, 0,
259259
"int main() {}",
260260
dinit(CheckOptions,
261-
$.showtime = ShowTime::FILE));
261+
$.showtime = Settings::ShowTime::FILE));
262262
const std::string output_s = GET_REDIRECT_OUTPUT;
263263
ASSERT_EQUALS(0, cppcheck::count_all_of(output_s, "Overall time:"));
264264
}
@@ -268,7 +268,7 @@ class TestThreadExecutorBase : public TestFixture {
268268
check(2, 2, 0,
269269
"int main() {}",
270270
dinit(CheckOptions,
271-
$.showtime = ShowTime::FILE_TOTAL));
271+
$.showtime = Settings::ShowTime::FILE_TOTAL));
272272
const std::string output_s = GET_REDIRECT_OUTPUT;
273273
ASSERT(output_s.find("Check time: " + fprefix() + "_1.c: ") != std::string::npos);
274274
ASSERT(output_s.find("Check time: " + fprefix() + "_2.c: ") != std::string::npos);

0 commit comments

Comments
 (0)