removed `CppCheck` dependency from `CppCheckExecutor::parseFromArgs()` (#4967)

* made `CppCheck::getErrorMessages()` static

* removed `CppCheck` dependency from `CppCheckExecutor::parseFromArgs()`
This commit is contained in:
Oliver Stöneberg 2023-04-16 13:54:21 +02:00 committed by GitHub
parent e575a84c8a
commit 9ad26f51e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 28 deletions

View File

@ -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);
@ -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;
}
@ -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;
if (cppCheck.settings().exceptionHandling)
int ret;
if (settings.exceptionHandling)
ret = check_wrapper(cppCheck);
else
ret = check_internal(cppCheck);

View File

@ -115,12 +115,12 @@ protected:
* @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:

View File

@ -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);

View File

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

View File

@ -116,7 +116,7 @@ public:
* @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);

View File

@ -75,8 +75,7 @@ private:
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