Skip to content

Commit 9ad26f5

Browse files
authored
removed CppCheck dependency from CppCheckExecutor::parseFromArgs() (#4967)
* made `CppCheck::getErrorMessages()` static * removed `CppCheck` dependency from `CppCheckExecutor::parseFromArgs()`
1 parent e575a84 commit 9ad26f5

File tree

6 files changed

+23
-28
lines changed

6 files changed

+23
-28
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ CppCheckExecutor::~CppCheckExecutor()
7878
delete mErrorOutput;
7979
}
8080

81-
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])
81+
bool CppCheckExecutor::parseFromArgs(Settings &settings, int argc, const char* const argv[])
8282
{
83-
Settings& settings = cppcheck->settings();
8483
CmdLineParser parser(settings);
8584
const bool success = parser.parseFromArgs(argc, argv);
8685

@@ -101,7 +100,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
101100
if (parser.getShowErrorMessages()) {
102101
mShowAllErrors = true;
103102
std::cout << ErrorMessage::getXMLHeader(settings.cppcheckCfgProductName);
104-
cppcheck->getErrorMessages();
103+
CppCheck::getErrorMessages(*this);
105104
std::cout << ErrorMessage::getXMLFooter() << std::endl;
106105
}
107106

@@ -199,23 +198,20 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
199198
{
200199
CheckUnusedFunctions::clear();
201200

202-
CppCheck cppCheck(*this, true, executeCommand);
203-
204-
const Settings& settings = cppCheck.settings();
205-
mSettings = &settings;
206-
207-
if (!parseFromArgs(&cppCheck, argc, argv)) {
208-
mSettings = nullptr;
201+
Settings settings;
202+
if (!parseFromArgs(settings, argc, argv)) {
209203
return EXIT_FAILURE;
210204
}
211205
if (Settings::terminated()) {
212-
mSettings = nullptr;
213206
return EXIT_SUCCESS;
214207
}
215208

216-
int ret;
209+
CppCheck cppCheck(*this, true, executeCommand);
210+
cppCheck.settings() = settings;
211+
mSettings = &settings;
217212

218-
if (cppCheck.settings().exceptionHandling)
213+
int ret;
214+
if (settings.exceptionHandling)
219215
ret = check_wrapper(cppCheck);
220216
else
221217
ret = check_internal(cppCheck);

cli/cppcheckexecutor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ class CppCheckExecutor : public ErrorLogger {
115115
* @brief Parse command line args and get settings and file lists
116116
* from there.
117117
*
118-
* @param cppcheck cppcheck instance
118+
* @param settings the settings to store into
119119
* @param argc argc from main()
120120
* @param argv argv from main()
121121
* @return false when errors are found in the input
122122
*/
123-
bool parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]);
123+
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);
124124

125125
private:
126126

gui/newsuppressiondialog.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
5050
};
5151

5252
QErrorLogger errorLogger;
53-
CppCheck cppcheck(errorLogger, false, nullptr);
54-
cppcheck.getErrorMessages();
53+
CppCheck::getErrorMessages(errorLogger);
5554
errorLogger.errorIds.sort();
5655

5756
mUI->mComboErrorId->addItems(errorLogger.errorIds);

lib/cppcheck.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,25 +1649,26 @@ void CppCheck::reportProgress(const std::string &filename, const char stage[], c
16491649
mErrorLogger.reportProgress(filename, stage, value);
16501650
}
16511651

1652-
void CppCheck::getErrorMessages()
1652+
void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
16531653
{
1654-
Settings s(mSettings);
1654+
Settings s;
16551655
s.severity.enable(Severity::warning);
16561656
s.severity.enable(Severity::style);
16571657
s.severity.enable(Severity::portability);
16581658
s.severity.enable(Severity::performance);
16591659
s.severity.enable(Severity::information);
16601660

1661-
purgedConfigurationMessage(emptyString,emptyString);
1662-
1663-
mTooManyConfigs = true;
1664-
tooManyConfigsError(emptyString,0U);
1661+
CppCheck cppcheck(errorlogger, true, nullptr);
1662+
cppcheck.purgedConfigurationMessage(emptyString,emptyString);
1663+
cppcheck.mTooManyConfigs = true;
1664+
cppcheck.tooManyConfigsError(emptyString,0U);
1665+
// TODO: add functions to get remaining error messages
16651666

16661667
// call all "getErrorMessages" in all registered Check classes
16671668
for (std::list<Check *>::const_iterator it = Check::instances().cbegin(); it != Check::instances().cend(); ++it)
1668-
(*it)->getErrorMessages(this, &s);
1669+
(*it)->getErrorMessages(&errorlogger, &s);
16691670

1670-
Preprocessor::getErrorMessages(this, &s);
1671+
Preprocessor::getErrorMessages(&errorlogger, &s);
16711672
}
16721673

16731674
void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)

lib/cppcheck.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
116116
* @brief Call all "getErrorMessages" in all registered Check classes.
117117
* Also print out XML header and footer.
118118
*/
119-
void getErrorMessages();
119+
static void getErrorMessages(ErrorLogger &errorlogger);
120120

121121
void tooManyConfigsError(const std::string &file, const int numberOfConfigurations);
122122
void purgedConfigurationMessage(const std::string &file, const std::string& configuration);

test/testcppcheck.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ class TestCppcheck : public TestFixture {
7575

7676
void getErrorMessages() const {
7777
ErrorLogger2 errorLogger;
78-
CppCheck cppCheck(errorLogger, true, nullptr);
79-
cppCheck.getErrorMessages();
78+
CppCheck::getErrorMessages(errorLogger);
8079
ASSERT(!errorLogger.id.empty());
8180

8281
// Check if there are duplicate error ids in errorLogger.id

0 commit comments

Comments
 (0)