Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ CppCheckExecutor::~CppCheckExecutor()
delete mErrorOutput;
}

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

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

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

CppCheck cppCheck(*this, true, executeCommand);

const Settings& settings = cppCheck.settings();
mSettings = &settings;

if (!parseFromArgs(&cppCheck, argc, argv)) {
mSettings = nullptr;
Settings settings;
if (!parseFromArgs(settings, argc, argv)) {
return EXIT_FAILURE;
}
if (Settings::terminated()) {
mSettings = nullptr;
return EXIT_SUCCESS;
}

int ret;
CppCheck cppCheck(*this, true, executeCommand);
cppCheck.settings() = settings;
mSettings = &settings;
Comment thread
danmar marked this conversation as resolved.

if (cppCheck.settings().exceptionHandling)
int ret;
if (settings.exceptionHandling)
ret = check_wrapper(cppCheck);
else
ret = check_internal(cppCheck);
Expand Down
4 changes: 2 additions & 2 deletions cli/cppcheckexecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ class CppCheckExecutor : public ErrorLogger {
* @brief Parse command line args and get settings and file lists
* from there.
*
* @param cppcheck cppcheck instance
* @param settings the settings to store into
* @param argc argc from main()
* @param argv argv from main()
* @return false when errors are found in the input
*/
bool parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[]);
bool parseFromArgs(Settings &settings, int argc, const char* const argv[]);

private:

Expand Down
3 changes: 1 addition & 2 deletions gui/newsuppressiondialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ NewSuppressionDialog::NewSuppressionDialog(QWidget *parent) :
};

QErrorLogger errorLogger;
CppCheck cppcheck(errorLogger, false, nullptr);
cppcheck.getErrorMessages();
CppCheck::getErrorMessages(errorLogger);
errorLogger.errorIds.sort();

mUI->mComboErrorId->addItems(errorLogger.errorIds);
Expand Down
17 changes: 9 additions & 8 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1649,25 +1649,26 @@ void CppCheck::reportProgress(const std::string &filename, const char stage[], c
mErrorLogger.reportProgress(filename, stage, value);
}

void CppCheck::getErrorMessages()
void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
{
Settings s(mSettings);
Settings s;
s.severity.enable(Severity::warning);
s.severity.enable(Severity::style);
s.severity.enable(Severity::portability);
s.severity.enable(Severity::performance);
s.severity.enable(Severity::information);

purgedConfigurationMessage(emptyString,emptyString);

mTooManyConfigs = true;
tooManyConfigsError(emptyString,0U);
CppCheck cppcheck(errorlogger, true, nullptr);
cppcheck.purgedConfigurationMessage(emptyString,emptyString);
cppcheck.mTooManyConfigs = true;
cppcheck.tooManyConfigsError(emptyString,0U);
// TODO: add functions to get remaining error messages

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

Preprocessor::getErrorMessages(this, &s);
Preprocessor::getErrorMessages(&errorlogger, &s);
}

void CppCheck::analyseClangTidy(const ImportProject::FileSettings &fileSettings)
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
* @brief Call all "getErrorMessages" in all registered Check classes.
* Also print out XML header and footer.
*/
void getErrorMessages();
static void getErrorMessages(ErrorLogger &errorlogger);

void tooManyConfigsError(const std::string &file, const int numberOfConfigurations);
void purgedConfigurationMessage(const std::string &file, const std::string& configuration);
Expand Down
3 changes: 1 addition & 2 deletions test/testcppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class TestCppcheck : public TestFixture {

void getErrorMessages() const {
ErrorLogger2 errorLogger;
CppCheck cppCheck(errorLogger, true, nullptr);
cppCheck.getErrorMessages();
CppCheck::getErrorMessages(errorLogger);
ASSERT(!errorLogger.id.empty());

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