diff --git a/Makefile b/Makefile index 60c16d87b2a..6cbb850ad46 100644 --- a/Makefile +++ b/Makefile @@ -491,7 +491,7 @@ $(libcppdir)/checkautovariables.o: lib/checkautovariables.cpp lib/addoninfo.h li $(libcppdir)/checkbool.o: lib/checkbool.cpp lib/addoninfo.h lib/astutils.h lib/check.h lib/checkbool.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkbool.cpp -$(libcppdir)/checkboost.o: lib/checkboost.cpp lib/addoninfo.h lib/check.h lib/checkboost.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h +$(libcppdir)/checkboost.o: lib/checkboost.cpp lib/check.h lib/checkboost.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/checkboost.cpp $(libcppdir)/checkbufferoverrun.o: lib/checkbufferoverrun.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/astutils.h lib/check.h lib/checkbufferoverrun.h lib/color.h lib/config.h lib/ctu.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h lib/xml.h @@ -593,7 +593,7 @@ $(libcppdir)/infer.o: lib/infer.cpp lib/calculate.h lib/config.h lib/errortypes. $(libcppdir)/keywords.o: lib/keywords.cpp lib/config.h lib/keywords.h lib/standards.h lib/utils.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/keywords.cpp -$(libcppdir)/library.o: lib/library.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h lib/xml.h +$(libcppdir)/library.o: lib/library.cpp externals/tinyxml2/tinyxml2.h lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h lib/xml.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/library.cpp $(libcppdir)/mathlib.o: lib/mathlib.cpp externals/simplecpp/simplecpp.h lib/config.h lib/errortypes.h lib/mathlib.h lib/utils.h @@ -626,7 +626,7 @@ $(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/addo $(libcppdir)/summaries.o: lib/summaries.cpp lib/addoninfo.h lib/analyzerinfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/summaries.cpp -$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h +$(libcppdir)/suppressions.o: lib/suppressions.cpp externals/tinyxml2/tinyxml2.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/mathlib.h lib/path.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h lib/xml.h $(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/suppressions.cpp $(libcppdir)/templatesimplifier.o: lib/templatesimplifier.cpp lib/addoninfo.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/templatesimplifier.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/vfvalue.h diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 82ef08a4179..4f4026ffb16 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -797,9 +797,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a } if (str == "c") - mSettings.enforcedLang = Settings::Language::C; + mSettings.enforcedLang = Standards::Language::C; else if (str == "c++") - mSettings.enforcedLang = Settings::Language::CPP; + mSettings.enforcedLang = Standards::Language::CPP; else { mLogger.printError("unknown language '" + str + "' enforced."); return Result::Fail; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 323f0255870..7f88449b635 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -392,10 +392,10 @@ void MainWindow::loadSettings() mUI->mActionToolBarFilter->setChecked(showFilterToolbar); mUI->mToolBarFilter->setVisible(showFilterToolbar); - const Settings::Language enforcedLanguage = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); - if (enforcedLanguage == Settings::CPP) + const Standards::Language enforcedLanguage = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); + if (enforcedLanguage == Standards::Language::CPP) mUI->mActionEnforceCpp->setChecked(true); - else if (enforcedLanguage == Settings::C) + else if (enforcedLanguage == Standards::Language::C) mUI->mActionEnforceC->setChecked(true); else mUI->mActionAutoDetectLanguage->setChecked(true); @@ -469,11 +469,11 @@ void MainWindow::saveSettings() const mSettings->setValue(SETTINGS_TOOLBARS_FILTER_SHOW, mUI->mToolBarFilter->isVisible()); if (mUI->mActionEnforceCpp->isChecked()) - mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Settings::CPP); + mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Standards::Language::CPP); else if (mUI->mActionEnforceC->isChecked()) - mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Settings::C); + mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Standards::Language::C); else - mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Settings::None); + mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Standards::Language::None); mApplications->saveSettings(); @@ -1091,7 +1091,7 @@ Settings MainWindow::getCppcheckSettings() result.platform.set((Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()); result.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString()); result.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString()); - result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); + result.enforcedLang = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); if (result.jobs <= 1) { result.jobs = 1; diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 521b3f10603..032a4a47049 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -188,13 +188,13 @@ static void createDumpFile(const Settings& settings, std::string language; switch (settings.enforcedLang) { - case Settings::Language::C: + case Standards::Language::C: language = " language=\"c\""; break; - case Settings::Language::CPP: + case Standards::Language::CPP: language = " language=\"cpp\""; break; - case Settings::Language::None: + case Standards::Language::None: if (Path::isCPP(filename)) language = " language=\"cpp\""; else if (Path::isC(filename)) diff --git a/lib/settings.h b/lib/settings.h index be106ef98c3..cfe63e7e404 100644 --- a/lib/settings.h +++ b/lib/settings.h @@ -182,12 +182,8 @@ class CPPCHECKLIB WARN_UNUSED Settings { bool dump{}; std::string dumpFile; - enum Language { - None, C, CPP - }; - /** @brief Name of the language that is enforced. Empty per default. */ - Language enforcedLang{}; + Standards::Language enforcedLang{}; #if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING) /** @brief Is --exception-handling given */ diff --git a/lib/standards.h b/lib/standards.h index 619ce623594..4b1469164ca 100644 --- a/lib/standards.h +++ b/lib/standards.h @@ -34,6 +34,8 @@ * This struct contains all possible standards that cppcheck recognize. */ struct Standards { + enum Language { None, C, CPP }; + /** C code standard */ enum cstd_t { C89, C99, C11, CLatest = C11 } c = CLatest; diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 5e45b8d57d3..4f482d6f177 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -50,7 +50,7 @@ TokenList::TokenList(const Settings* settings) : mSettings(settings) { mTokensFrontBack.list = this; - if (mSettings && (mSettings->enforcedLang != Settings::Language::None)) { + if (mSettings && (mSettings->enforcedLang != Standards::Language::None)) { mLang = mSettings->enforcedLang; } } @@ -84,11 +84,11 @@ void TokenList::deallocateTokens() void TokenList::determineCppC() { // only try to determine it if it wasn't enforced - if (mLang == Settings::Language::None) { + if (mLang == Standards::Language::None) { if (Path::isC(getSourceFilePath())) - mLang = Settings::Language::C; + mLang = Standards::Language::C; else if (Path::isCPP(getSourceFilePath())) - mLang = Settings::Language::CPP; + mLang = Standards::Language::CPP; } } diff --git a/lib/tokenlist.h b/lib/tokenlist.h index 39c58255fb4..3b71d07d156 100644 --- a/lib/tokenlist.h +++ b/lib/tokenlist.h @@ -22,7 +22,7 @@ //--------------------------------------------------------------------------- #include "config.h" -#include "settings.h" +#include "standards.h" #include #include @@ -31,6 +31,7 @@ class Token; class TokenList; +class Settings; namespace simplecpp { class TokenList; @@ -61,12 +62,12 @@ class CPPCHECKLIB TokenList { /** Is the code C. Used for bailouts */ bool isC() const { - return mLang == Settings::Language::C; + return mLang == Standards::Language::C; } /** Is the code CPP. Used for bailouts */ bool isCPP() const { - return mLang == Settings::Language::CPP; + return mLang == Standards::Language::CPP; } /** @@ -214,7 +215,7 @@ class CPPCHECKLIB TokenList { const Settings* const mSettings{}; /** File is known to be C/C++ code */ - Settings::Language mLang{Settings::Language::None}; + Standards::Language mLang{Standards::Language::None}; }; /// @} diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index 2cb87695e0f..69829ca89fd 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -631,17 +631,17 @@ class TestCmdlineParser : public TestFixture { void enforceLanguage1() { REDIRECT; const char * const argv[] = {"cppcheck", "file.cpp"}; - settings->enforcedLang = Settings::Language::None; + settings->enforcedLang = Standards::Language::None; ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(2, argv)); - ASSERT_EQUALS(Settings::Language::None, settings->enforcedLang); + ASSERT_EQUALS(Standards::Language::None, settings->enforcedLang); } void enforceLanguage2() { REDIRECT; const char * const argv[] = {"cppcheck", "-x", "c++", "file.cpp"}; - settings->enforcedLang = Settings::Language::None; + settings->enforcedLang = Standards::Language::None; ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv)); - ASSERT_EQUALS(Settings::Language::CPP, settings->enforcedLang); + ASSERT_EQUALS(Standards::Language::CPP, settings->enforcedLang); } void enforceLanguage3() { @@ -661,17 +661,17 @@ class TestCmdlineParser : public TestFixture { void enforceLanguage5() { REDIRECT; const char * const argv[] = {"cppcheck", "--language=c++", "file.cpp"}; - settings->enforcedLang = Settings::Language::None; + settings->enforcedLang = Standards::Language::None; ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); - ASSERT_EQUALS(Settings::Language::CPP, settings->enforcedLang); + ASSERT_EQUALS(Standards::Language::CPP, settings->enforcedLang); } void enforceLanguage6() { REDIRECT; const char * const argv[] = {"cppcheck", "--language=c", "file.cpp"}; - settings->enforcedLang = Settings::Language::None; + settings->enforcedLang = Standards::Language::None; ASSERT_EQUALS(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv)); - ASSERT_EQUALS(Settings::Language::C, settings->enforcedLang); + ASSERT_EQUALS(Standards::Language::C, settings->enforcedLang); } void enforceLanguage7() { diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index a4237aefa2d..6e4645a7832 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -1822,7 +1822,7 @@ class TestUnusedVar : public TestFixture { errout.str()); Settings s = settings; - s.enforcedLang = Settings::C; + s.enforcedLang = Standards::Language::C; checkStructMemberUsage("struct A {\n" // #10852 " struct B {\n" " int x;\n"