Skip to content

Commit 94becd2

Browse files
committed
made CheckLevel a parameter in the setter functions
1 parent 1a275b4 commit 94becd2

7 files changed

Lines changed: 28 additions & 37 deletions

File tree

cli/cmdlineparser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
312312
mSettings.exename = Path::getCurrentExecutablePath(argv[0]);
313313

314314
// default to --check-level=normal from CLI for now
315-
mSettings.setCheckLevelNormal();
315+
mSettings.setCheckLevel(Settings::CheckLevel::normal);
316316

317317
if (argc <= 1) {
318318
printHelp();
@@ -473,11 +473,11 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
473473

474474
// Check code exhaustively
475475
else if (std::strcmp(argv[i], "--check-level=exhaustive") == 0)
476-
mSettings.setCheckLevelExhaustive();
476+
mSettings.setCheckLevel(Settings::CheckLevel::exhaustive);
477477

478478
// Check code with normal analysis
479479
else if (std::strcmp(argv[i], "--check-level=normal") == 0)
480-
mSettings.setCheckLevelNormal();
480+
mSettings.setCheckLevel(Settings::CheckLevel::normal);
481481

482482
// Check library definitions
483483
else if (std::strcmp(argv[i], "--check-library") == 0) {

gui/mainwindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
970970
result.exename = QCoreApplication::applicationFilePath().toStdString();
971971

972972
// default to --check-level=normal for GUI for now
973-
result.setCheckLevelNormal();
973+
result.setCheckLevel(Settings::CheckLevel::normal);
974974

975975
const bool std = tryLoadLibrary(&result.library, "std.cfg");
976976
if (!std) {
@@ -1064,9 +1064,9 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
10641064
result.maxCtuDepth = mProjectFile->getMaxCtuDepth();
10651065
result.maxTemplateRecursion = mProjectFile->getMaxTemplateRecursion();
10661066
if (mProjectFile->isCheckLevelExhaustive())
1067-
result.setCheckLevelExhaustive();
1067+
result.setCheckLevel(Settings::CheckLevel::exhaustive);
10681068
else
1069-
result.setCheckLevelNormal();
1069+
result.setCheckLevel(Settings::CheckLevel::normal);
10701070
result.checkHeaders = mProjectFile->getCheckHeaders();
10711071
result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates();
10721072
result.safeChecks.classes = mProjectFile->safeChecks.classes;

lib/importproject.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
11261126
Settings temp;
11271127

11281128
// default to --check-level=normal for import for now
1129-
temp.setCheckLevelNormal();
1129+
temp.setCheckLevel(Settings::CheckLevel::normal);
11301130

11311131
guiProject.analyzeAllVsConfigs.clear();
11321132

@@ -1271,9 +1271,9 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
12711271
settings->safeChecks = temp.safeChecks;
12721272

12731273
if (checkLevelExhaustive)
1274-
settings->setCheckLevelExhaustive();
1274+
settings->setCheckLevel(Settings::CheckLevel::exhaustive);
12751275
else
1276-
settings->setCheckLevelNormal();
1276+
settings->setCheckLevel(Settings::CheckLevel::normal);
12771277

12781278
return true;
12791279
}

lib/settings.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Settings::Settings()
4141
{
4242
severity.setEnabled(Severity::error, true);
4343
certainty.setEnabled(Certainty::normal, true);
44-
setCheckLevelExhaustive();
44+
setCheckLevel(Settings::CheckLevel::exhaustive);
4545
executor = defaultExecutor();
4646
}
4747

@@ -268,21 +268,20 @@ void Settings::loadSummaries()
268268
Summaries::loadReturn(buildDir, summaryReturn);
269269
}
270270

271-
272-
void Settings::setCheckLevelExhaustive()
273-
{
274-
// Checking can take a little while. ~ 10 times slower than normal analysis is OK.
275-
checkLevel = CheckLevel::exhaustive;
276-
performanceValueFlowMaxIfCount = -1;
277-
performanceValueFlowMaxSubFunctionArgs = 256;
278-
}
279-
280-
void Settings::setCheckLevelNormal()
271+
void Settings::setCheckLevel(CheckLevel level)
281272
{
282-
// Checking should finish in reasonable time.
283-
checkLevel = CheckLevel::normal;
284-
performanceValueFlowMaxSubFunctionArgs = 8;
285-
performanceValueFlowMaxIfCount = 100;
273+
if (level == CheckLevel::normal) {
274+
// Checking should finish in reasonable time.
275+
checkLevel = level;
276+
performanceValueFlowMaxSubFunctionArgs = 8;
277+
performanceValueFlowMaxIfCount = 100;
278+
}
279+
else if (level == CheckLevel::exhaustive) {
280+
// Checking can take a little while. ~ 10 times slower than normal analysis is OK.
281+
checkLevel = CheckLevel::exhaustive;
282+
performanceValueFlowMaxIfCount = -1;
283+
performanceValueFlowMaxSubFunctionArgs = 256;
284+
}
286285
}
287286

288287
// TODO: auto generate these tables

lib/settings.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,15 +456,14 @@ class CPPCHECKLIB WARN_UNUSED Settings {
456456
return jobs == 1;
457457
}
458458

459-
void setCheckLevelExhaustive();
460-
void setCheckLevelNormal();
461-
462459
enum class CheckLevel {
463460
normal,
464461
exhaustive
465462
};
466463
CheckLevel checkLevel = CheckLevel::exhaustive;
467464

465+
void setCheckLevel(CheckLevel level);
466+
468467
using ExecuteCmdFn = std::function<int (std::string,std::vector<std::string>,std::string,std::string&)>;
469468
void setMisraRuleTexts(const ExecuteCmdFn& executeCommand);
470469
void setMisraRuleTexts(const std::string& data);

test/fixture.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,8 @@ void TestFixture::setTemplateFormat(const std::string &templateFormat)
445445
}
446446
}
447447

448-
TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::normal() {
449-
settings.setCheckLevelNormal();
450-
return *this;
451-
}
452-
453-
TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::exhaustive() {
454-
settings.setCheckLevelExhaustive();
448+
TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::checkLevel(Settings::CheckLevel level) {
449+
settings.setCheckLevel(level);
455450
return *this;
456451
}
457452

test/fixture.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,7 @@ class TestFixture : public ErrorLogger {
208208
return *this;
209209
}
210210

211-
SettingsBuilder& exhaustive();
212-
213-
SettingsBuilder& normal();
211+
SettingsBuilder& checkLevel(Settings::CheckLevel level);
214212

215213
SettingsBuilder& library(const char lib[]);
216214

0 commit comments

Comments
 (0)