Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moved Language from settings.h to standards.h #5854

Merged
merged 1 commit into from
Jan 7, 2024
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 1 addition & 5 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions lib/standards.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions lib/tokenlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}

Expand Down
9 changes: 5 additions & 4 deletions lib/tokenlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
//---------------------------------------------------------------------------

#include "config.h"
#include "settings.h"
#include "standards.h"

#include <cstddef>
#include <iosfwd>
Expand All @@ -31,6 +31,7 @@

class Token;
class TokenList;
class Settings;

namespace simplecpp {
class TokenList;
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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};
};

/// @}
Expand Down
16 changes: 8 additions & 8 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading