Skip to content

Commit

Permalink
made CheckLevel a parameter in the setter functions
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 11, 2024
1 parent dcbafa6 commit 8d480b3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 37 deletions.
6 changes: 3 additions & 3 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
mSettings.exename = Path::getCurrentExecutablePath(argv[0]);

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

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

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

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

// Check library definitions
else if (std::strcmp(argv[i], "--check-library") == 0) {
Expand Down
6 changes: 3 additions & 3 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
result.exename = QCoreApplication::applicationFilePath().toStdString();

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

const bool std = tryLoadLibrary(&result.library, "std.cfg");
if (!std) {
Expand Down Expand Up @@ -1064,9 +1064,9 @@ QPair<bool,Settings> MainWindow::getCppcheckSettings()
result.maxCtuDepth = mProjectFile->getMaxCtuDepth();
result.maxTemplateRecursion = mProjectFile->getMaxTemplateRecursion();
if (mProjectFile->isCheckLevelExhaustive())
result.setCheckLevelExhaustive();
result.setCheckLevel(Settings::CheckLevel::exhaustive);
else
result.setCheckLevelNormal();
result.setCheckLevel(Settings::CheckLevel::normal);
result.checkHeaders = mProjectFile->getCheckHeaders();
result.checkUnusedTemplates = mProjectFile->getCheckUnusedTemplates();
result.safeChecks.classes = mProjectFile->safeChecks.classes;
Expand Down
6 changes: 3 additions & 3 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
Settings temp;

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

guiProject.analyzeAllVsConfigs.clear();

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

if (checkLevelExhaustive)
settings->setCheckLevelExhaustive();
settings->setCheckLevel(Settings::CheckLevel::exhaustive);
else
settings->setCheckLevelNormal();
settings->setCheckLevel(Settings::CheckLevel::normal);

return true;
}
Expand Down
29 changes: 14 additions & 15 deletions lib/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Settings::Settings()
{
severity.setEnabled(Severity::error, true);
certainty.setEnabled(Certainty::normal, true);
setCheckLevelExhaustive();
setCheckLevel(Settings::CheckLevel::exhaustive);
executor = defaultExecutor();
}

Expand Down Expand Up @@ -268,21 +268,20 @@ void Settings::loadSummaries()
Summaries::loadReturn(buildDir, summaryReturn);
}


void Settings::setCheckLevelExhaustive()
{
// Checking can take a little while. ~ 10 times slower than normal analysis is OK.
checkLevel = CheckLevel::exhaustive;
performanceValueFlowMaxIfCount = -1;
performanceValueFlowMaxSubFunctionArgs = 256;
}

void Settings::setCheckLevelNormal()
void Settings::setCheckLevel(CheckLevel level)
{
// Checking should finish in reasonable time.
checkLevel = CheckLevel::normal;
performanceValueFlowMaxSubFunctionArgs = 8;
performanceValueFlowMaxIfCount = 100;
if (level == CheckLevel::normal) {
// Checking should finish in reasonable time.
checkLevel = level;
performanceValueFlowMaxSubFunctionArgs = 8;
performanceValueFlowMaxIfCount = 100;
}
else if (level == CheckLevel::exhaustive) {
// Checking can take a little while. ~ 10 times slower than normal analysis is OK.
checkLevel = CheckLevel::exhaustive;
performanceValueFlowMaxIfCount = -1;
performanceValueFlowMaxSubFunctionArgs = 256;
}
}

// TODO: auto generate these tables
Expand Down
5 changes: 2 additions & 3 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,14 @@ class CPPCHECKLIB WARN_UNUSED Settings {
return jobs == 1;
}

void setCheckLevelExhaustive();
void setCheckLevelNormal();

enum class CheckLevel {
normal,
exhaustive
};
CheckLevel checkLevel = CheckLevel::exhaustive;

void setCheckLevel(CheckLevel level);

using ExecuteCmdFn = std::function<int (std::string,std::vector<std::string>,std::string,std::string&)>;
void setMisraRuleTexts(const ExecuteCmdFn& executeCommand);
void setMisraRuleTexts(const std::string& data);
Expand Down
9 changes: 2 additions & 7 deletions test/fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,13 +445,8 @@ void TestFixture::setTemplateFormat(const std::string &templateFormat)
}
}

TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::normal() {
settings.setCheckLevelNormal();
return *this;
}

TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::exhaustive() {
settings.setCheckLevelExhaustive();
TestFixture::SettingsBuilder& TestFixture::SettingsBuilder::checkLevel(Settings::CheckLevel level) {
settings.setCheckLevel(level);
return *this;
}

Expand Down
4 changes: 1 addition & 3 deletions test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ class TestFixture : public ErrorLogger {
return *this;
}

SettingsBuilder& exhaustive();

SettingsBuilder& normal();
SettingsBuilder& checkLevel(Settings::CheckLevel level);

SettingsBuilder& library(const char lib[]);

Expand Down

0 comments on commit 8d480b3

Please sign in to comment.