moved `Language` from `settings.h` to `standards.h` (#5854)

This commit is contained in:
Oliver Stöneberg 2024-01-07 22:53:39 +01:00 committed by GitHub
parent bbd2b2aa83
commit 30ca8e11b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 36 additions and 37 deletions

View File

@ -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 $(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 $(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 $(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 $(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 $(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 $(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 $(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 $(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 $(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 $(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 $(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 $(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

View File

@ -798,9 +798,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
} }
if (str == "c") if (str == "c")
mSettings.enforcedLang = Settings::Language::C; mSettings.enforcedLang = Standards::Language::C;
else if (str == "c++") else if (str == "c++")
mSettings.enforcedLang = Settings::Language::CPP; mSettings.enforcedLang = Standards::Language::CPP;
else { else {
mLogger.printError("unknown language '" + str + "' enforced."); mLogger.printError("unknown language '" + str + "' enforced.");
return Result::Fail; return Result::Fail;

View File

@ -392,10 +392,10 @@ void MainWindow::loadSettings()
mUI->mActionToolBarFilter->setChecked(showFilterToolbar); mUI->mActionToolBarFilter->setChecked(showFilterToolbar);
mUI->mToolBarFilter->setVisible(showFilterToolbar); mUI->mToolBarFilter->setVisible(showFilterToolbar);
const Settings::Language enforcedLanguage = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt(); const Standards::Language enforcedLanguage = (Standards::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
if (enforcedLanguage == Settings::CPP) if (enforcedLanguage == Standards::Language::CPP)
mUI->mActionEnforceCpp->setChecked(true); mUI->mActionEnforceCpp->setChecked(true);
else if (enforcedLanguage == Settings::C) else if (enforcedLanguage == Standards::Language::C)
mUI->mActionEnforceC->setChecked(true); mUI->mActionEnforceC->setChecked(true);
else else
mUI->mActionAutoDetectLanguage->setChecked(true); mUI->mActionAutoDetectLanguage->setChecked(true);
@ -469,11 +469,11 @@ void MainWindow::saveSettings() const
mSettings->setValue(SETTINGS_TOOLBARS_FILTER_SHOW, mUI->mToolBarFilter->isVisible()); mSettings->setValue(SETTINGS_TOOLBARS_FILTER_SHOW, mUI->mToolBarFilter->isVisible());
if (mUI->mActionEnforceCpp->isChecked()) if (mUI->mActionEnforceCpp->isChecked())
mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Settings::CPP); mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Standards::Language::CPP);
else if (mUI->mActionEnforceC->isChecked()) else if (mUI->mActionEnforceC->isChecked())
mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Settings::C); mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Standards::Language::C);
else else
mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Settings::None); mSettings->setValue(SETTINGS_ENFORCED_LANGUAGE, Standards::Language::None);
mApplications->saveSettings(); mApplications->saveSettings();
@ -1091,7 +1091,7 @@ Settings MainWindow::getCppcheckSettings()
result.platform.set((Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()); 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.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
result.standards.setC(mSettings->value(SETTINGS_STD_C, 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) { if (result.jobs <= 1) {
result.jobs = 1; result.jobs = 1;

View File

@ -188,13 +188,13 @@ static void createDumpFile(const Settings& settings,
std::string language; std::string language;
switch (settings.enforcedLang) { switch (settings.enforcedLang) {
case Settings::Language::C: case Standards::Language::C:
language = " language=\"c\""; language = " language=\"c\"";
break; break;
case Settings::Language::CPP: case Standards::Language::CPP:
language = " language=\"cpp\""; language = " language=\"cpp\"";
break; break;
case Settings::Language::None: case Standards::Language::None:
if (Path::isCPP(filename)) if (Path::isCPP(filename))
language = " language=\"cpp\""; language = " language=\"cpp\"";
else if (Path::isC(filename)) else if (Path::isC(filename))

View File

@ -182,12 +182,8 @@ public:
bool dump{}; bool dump{};
std::string dumpFile; std::string dumpFile;
enum Language {
None, C, CPP
};
/** @brief Name of the language that is enforced. Empty per default. */ /** @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) #if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
/** @brief Is --exception-handling given */ /** @brief Is --exception-handling given */

View File

@ -34,6 +34,8 @@
* This struct contains all possible standards that cppcheck recognize. * This struct contains all possible standards that cppcheck recognize.
*/ */
struct Standards { struct Standards {
enum Language { None, C, CPP };
/** C code standard */ /** C code standard */
enum cstd_t { C89, C99, C11, CLatest = C11 } c = CLatest; enum cstd_t { C89, C99, C11, CLatest = C11 } c = CLatest;

View File

@ -50,7 +50,7 @@ TokenList::TokenList(const Settings* settings) :
mSettings(settings) mSettings(settings)
{ {
mTokensFrontBack.list = this; mTokensFrontBack.list = this;
if (mSettings && (mSettings->enforcedLang != Settings::Language::None)) { if (mSettings && (mSettings->enforcedLang != Standards::Language::None)) {
mLang = mSettings->enforcedLang; mLang = mSettings->enforcedLang;
} }
} }
@ -84,11 +84,11 @@ void TokenList::deallocateTokens()
void TokenList::determineCppC() void TokenList::determineCppC()
{ {
// only try to determine it if it wasn't enforced // only try to determine it if it wasn't enforced
if (mLang == Settings::Language::None) { if (mLang == Standards::Language::None) {
if (Path::isC(getSourceFilePath())) if (Path::isC(getSourceFilePath()))
mLang = Settings::Language::C; mLang = Standards::Language::C;
else if (Path::isCPP(getSourceFilePath())) else if (Path::isCPP(getSourceFilePath()))
mLang = Settings::Language::CPP; mLang = Standards::Language::CPP;
} }
} }

View File

@ -22,7 +22,7 @@
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
#include "config.h" #include "config.h"
#include "settings.h" #include "standards.h"
#include <cstddef> #include <cstddef>
#include <iosfwd> #include <iosfwd>
@ -31,6 +31,7 @@
class Token; class Token;
class TokenList; class TokenList;
class Settings;
namespace simplecpp { namespace simplecpp {
class TokenList; class TokenList;
@ -61,12 +62,12 @@ public:
/** Is the code C. Used for bailouts */ /** Is the code C. Used for bailouts */
bool isC() const { bool isC() const {
return mLang == Settings::Language::C; return mLang == Standards::Language::C;
} }
/** Is the code CPP. Used for bailouts */ /** Is the code CPP. Used for bailouts */
bool isCPP() const { bool isCPP() const {
return mLang == Settings::Language::CPP; return mLang == Standards::Language::CPP;
} }
/** /**
@ -214,7 +215,7 @@ private:
const Settings* const mSettings{}; const Settings* const mSettings{};
/** File is known to be C/C++ code */ /** File is known to be C/C++ code */
Settings::Language mLang{Settings::Language::None}; Standards::Language mLang{Standards::Language::None};
}; };
/// @} /// @}

View File

@ -632,17 +632,17 @@ private:
void enforceLanguage1() { void enforceLanguage1() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "file.cpp"}; 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(CmdLineParser::Result::Success, parser->parseFromArgs(2, argv));
ASSERT_EQUALS(Settings::Language::None, settings->enforcedLang); ASSERT_EQUALS(Standards::Language::None, settings->enforcedLang);
} }
void enforceLanguage2() { void enforceLanguage2() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "-x", "c++", "file.cpp"}; 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(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
ASSERT_EQUALS(Settings::Language::CPP, settings->enforcedLang); ASSERT_EQUALS(Standards::Language::CPP, settings->enforcedLang);
} }
void enforceLanguage3() { void enforceLanguage3() {
@ -662,17 +662,17 @@ private:
void enforceLanguage5() { void enforceLanguage5() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--language=c++", "file.cpp"}; 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(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
ASSERT_EQUALS(Settings::Language::CPP, settings->enforcedLang); ASSERT_EQUALS(Standards::Language::CPP, settings->enforcedLang);
} }
void enforceLanguage6() { void enforceLanguage6() {
REDIRECT; REDIRECT;
const char * const argv[] = {"cppcheck", "--language=c", "file.cpp"}; 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(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
ASSERT_EQUALS(Settings::Language::C, settings->enforcedLang); ASSERT_EQUALS(Standards::Language::C, settings->enforcedLang);
} }
void enforceLanguage7() { void enforceLanguage7() {

View File

@ -1822,7 +1822,7 @@ private:
errout.str()); errout.str());
Settings s = settings; Settings s = settings;
s.enforcedLang = Settings::C; s.enforcedLang = Standards::Language::C;
checkStructMemberUsage("struct A {\n" // #10852 checkStructMemberUsage("struct A {\n" // #10852
" struct B {\n" " struct B {\n"
" int x;\n" " int x;\n"