Skip to content

Commit 91e167e

Browse files
committed
moved ShowTime from timer.h to settings.h [skip ci]
1 parent 445ea21 commit 91e167e

9 files changed

Lines changed: 44 additions & 45 deletions

cli/cmdlineparser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1430,17 +1430,17 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
14301430
else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
14311431
const std::string showtimeMode = argv[i] + 11;
14321432
if (showtimeMode == "file")
1433-
mSettings.showtime = ShowTime::FILE;
1433+
mSettings.showtime = Settings::ShowTime::FILE;
14341434
else if (showtimeMode == "file-total")
1435-
mSettings.showtime = ShowTime::FILE_TOTAL;
1435+
mSettings.showtime = Settings::ShowTime::FILE_TOTAL;
14361436
else if (showtimeMode == "summary")
1437-
mSettings.showtime = ShowTime::SUMMARY;
1437+
mSettings.showtime = Settings::ShowTime::SUMMARY;
14381438
else if (showtimeMode == "top5_file")
1439-
mSettings.showtime = ShowTime::TOP5_FILE;
1439+
mSettings.showtime = Settings::ShowTime::TOP5_FILE;
14401440
else if (showtimeMode == "top5_summary")
1441-
mSettings.showtime = ShowTime::TOP5_SUMMARY;
1441+
mSettings.showtime = Settings::ShowTime::TOP5_SUMMARY;
14421442
else if (showtimeMode == "none")
1443-
mSettings.showtime = ShowTime::NONE;
1443+
mSettings.showtime = Settings::ShowTime::NONE;
14441444
else if (showtimeMode.empty()) {
14451445
mLogger.printError("no mode provided for --showtime");
14461446
return Result::Fail;

cli/cppcheckexecutor.cpp

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

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

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

427427
if (settings.reportProgress >= 0)
@@ -467,9 +467,9 @@ int CppCheckExecutor::check_internal(const Settings& settings, Suppressions& sup
467467

468468
// TODO: show time *after* the whole program analysis
469469
if (timerResults) {
470-
if (settings.showtime == ShowTime::SUMMARY)
470+
if (settings.showtime == Settings::ShowTime::SUMMARY)
471471
timerResults->showResults();
472-
else if (settings.showtime == ShowTime::TOP5_SUMMARY)
472+
else if (settings.showtime == Settings::ShowTime::TOP5_SUMMARY)
473473
timerResults->showResults(5);
474474
}
475475

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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@
3333
#include <utility>
3434
#include <vector>
3535

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

test/testcmdlineparser.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,21 +2193,21 @@ class TestCmdlineParser : public TestFixture {
21932193
REDIRECT;
21942194
const char * const argv[] = {"cppcheck", "--showtime=summary", "file.cpp"};
21952195
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2196-
ASSERT(settings->showtime == ShowTime::SUMMARY);
2196+
ASSERT_EQUALS_ENUM(Settings::ShowTime::SUMMARY, settings->showtime);
21972197
}
21982198

21992199
void showtimeFile() {
22002200
REDIRECT;
22012201
const char * const argv[] = {"cppcheck", "--showtime=file", "file.cpp"};
22022202
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2203-
ASSERT(settings->showtime == ShowTime::FILE);
2203+
ASSERT_EQUALS_ENUM(Settings::ShowTime::FILE, settings->showtime);
22042204
}
22052205

22062206
void showtimeFileTotal() {
22072207
REDIRECT;
22082208
const char * const argv[] = {"cppcheck", "--showtime=file-total", "file.cpp"};
22092209
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2210-
ASSERT(settings->showtime == ShowTime::FILE_TOTAL);
2210+
ASSERT_EQUALS_ENUM(Settings::ShowTime::FILE_TOTAL, settings->showtime);
22112211
}
22122212

22132213
void showtimeTop5() {
@@ -2221,21 +2221,21 @@ class TestCmdlineParser : public TestFixture {
22212221
REDIRECT;
22222222
const char * const argv[] = {"cppcheck", "--showtime=top5_file", "file.cpp"};
22232223
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2224-
ASSERT(settings->showtime == ShowTime::TOP5_FILE);
2224+
ASSERT_EQUALS_ENUM(Settings::ShowTime::TOP5_FILE, settings->showtime);
22252225
}
22262226

22272227
void showtimeTop5Summary() {
22282228
REDIRECT;
22292229
const char * const argv[] = {"cppcheck", "--showtime=top5_summary", "file.cpp"};
22302230
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2231-
ASSERT(settings->showtime == ShowTime::TOP5_SUMMARY);
2231+
ASSERT_EQUALS_ENUM(Settings::ShowTime::TOP5_SUMMARY, settings->showtime);
22322232
}
22332233

22342234
void showtimeNone() {
22352235
REDIRECT;
22362236
const char * const argv[] = {"cppcheck", "--showtime=none", "file.cpp"};
22372237
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parseFromArgs(argv));
2238-
ASSERT(settings->showtime == ShowTime::NONE);
2238+
ASSERT_EQUALS_ENUM(Settings::ShowTime::NONE, settings->showtime);
22392239
}
22402240

22412241
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)