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

View File

@ -798,9 +798,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;

View File

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

View File

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

View File

@ -182,12 +182,8 @@ public:
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 */

View File

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

View File

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

View File

@ -22,7 +22,7 @@
//---------------------------------------------------------------------------
#include "config.h"
#include "settings.h"
#include "standards.h"
#include <cstddef>
#include <iosfwd>
@ -31,6 +31,7 @@
class Token;
class TokenList;
class Settings;
namespace simplecpp {
class TokenList;
@ -61,12 +62,12 @@ public:
/** 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 @@ private:
const Settings* const mSettings{};
/** 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() {
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() {
@ -662,17 +662,17 @@ private:
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() {

View File

@ -1822,7 +1822,7 @@ private:
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"