Skip to content

Commit 5af6ca6

Browse files
authored
made Platform a member of Settings instead of inheriting from it / cleanups (cppcheck-opensource#4791)
1 parent 8023eff commit 5af6ca6

48 files changed

Lines changed: 756 additions & 755 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cli/cmdlineparser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
608608

609609
std::string errstr;
610610
const std::vector<std::string> paths = {argv[0]};
611-
if (!mSettings->platform(platform, errstr, paths)) {
611+
if (!mSettings->platform.set(platform, errstr, paths)) {
612612
printError(errstr);
613613
return false;
614614
}
@@ -621,9 +621,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
621621
// these are loaded via external files and thus have Settings::PlatformFile set instead.
622622
// override the type so they behave like the regular platforms.
623623
if (platform == "unix32-unsigned")
624-
mSettings->platformType = Settings::Unix32;
624+
mSettings->platform.type = cppcheck::Platform::Type::Unix32;
625625
else if (platform == "unix64-unsigned")
626-
mSettings->platformType = Settings::Unix64;
626+
mSettings->platform.type = cppcheck::Platform::Type::Unix64;
627627
}
628628

629629
// Write results in results.plist
@@ -679,7 +679,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
679679

680680
std::string errstr;
681681
const std::vector<std::string> paths = {projectFile, argv[0]};
682-
if (!mSettings->platform(platform, errstr, paths)) {
682+
if (!mSettings->platform.set(platform, errstr, paths)) {
683683
printError(errstr);
684684
return false;
685685
}
@@ -692,7 +692,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
692692
}
693693
if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
694694
if (mSettings->project.guiProject.analyzeAllVsConfigs == "false")
695-
mSettings->project.selectOneVsConfig(mSettings->platformType);
695+
mSettings->project.selectOneVsConfig(mSettings->platform.type);
696696
if (!CppCheckExecutor::tryLoadLibrary(mSettings->library, argv[0], "windows.cfg")) {
697697
// This shouldn't happen normally.
698698
printError("failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");

gui/mainwindow.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
257257
// For other platforms default to unspecified/default which means the
258258
// platform Cppcheck GUI was compiled on.
259259
#if defined(_WIN32)
260-
const cppcheck::Platform::PlatformType defaultPlatform = cppcheck::Platform::Win32W;
260+
const cppcheck::Platform::Type defaultPlatform = cppcheck::Platform::Type::Win32W;
261261
#else
262-
const cppcheck::Platform::PlatformType defaultPlatform = cppcheck::Platform::Unspecified;
262+
const cppcheck::Platform::Type defaultPlatform = cppcheck::Platform::Type::Unspecified;
263263
#endif
264-
Platform &platform = mPlatforms.get((cppcheck::Platform::PlatformType)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
264+
Platform &platform = mPlatforms.get((cppcheck::Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
265265
platform.mActMainWindow->setChecked(true);
266266

267267
mNetworkAccessManager = new QNetworkAccessManager(this);
@@ -477,7 +477,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
477477
p.ignorePaths(v);
478478

479479
if (!mProjectFile->getAnalyzeAllVsConfigs()) {
480-
const cppcheck::Platform::PlatformType platform = (cppcheck::Platform::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
480+
const cppcheck::Platform::Type platform = (cppcheck::Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
481481
p.selectOneVsConfig(platform);
482482
}
483483
} else {
@@ -941,12 +941,12 @@ Settings MainWindow::getCppcheckSettings()
941941
const QString platform = mProjectFile->getPlatform();
942942
if (platform.endsWith(".xml")) {
943943
const QString applicationFilePath = QCoreApplication::applicationFilePath();
944-
result.loadPlatformFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
944+
result.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
945945
} else {
946-
for (int i = cppcheck::Platform::Native; i <= cppcheck::Platform::Unix64; i++) {
947-
const cppcheck::Platform::PlatformType p = (cppcheck::Platform::PlatformType)i;
948-
if (platform == cppcheck::Platform::platformString(p)) {
949-
result.platform(p);
946+
for (int i = cppcheck::Platform::Type::Native; i <= cppcheck::Platform::Type::Unix64; i++) {
947+
const cppcheck::Platform::Type p = (cppcheck::Platform::Type)i;
948+
if (platform == cppcheck::Platform::toString(p)) {
949+
result.platform.set(p);
950950
break;
951951
}
952952
}
@@ -1029,8 +1029,8 @@ Settings MainWindow::getCppcheckSettings()
10291029
result.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
10301030
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();
10311031
result.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
1032-
if (!mProjectFile || result.platformType == cppcheck::Platform::Unspecified)
1033-
result.platform((cppcheck::Platform::PlatformType) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
1032+
if (!mProjectFile || result.platform.type == cppcheck::Platform::Type::Unspecified)
1033+
result.platform.set((cppcheck::Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
10341034
result.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
10351035
result.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString());
10361036
result.enforcedLang = (Settings::Language)mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt();
@@ -1908,7 +1908,7 @@ void MainWindow::selectPlatform()
19081908
{
19091909
QAction *action = qobject_cast<QAction *>(sender());
19101910
if (action) {
1911-
const cppcheck::Platform::PlatformType platform = (cppcheck::Platform::PlatformType) action->data().toInt();
1911+
const cppcheck::Platform::Type platform = (cppcheck::Platform::Type) action->data().toInt();
19121912
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
19131913
}
19141914
}

gui/platforms.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Platforms::Platforms(QObject *parent)
2424
init();
2525
}
2626

27-
void Platforms::add(const QString &title, cppcheck::Platform::PlatformType platform)
27+
void Platforms::add(const QString &title, cppcheck::Platform::Type platform)
2828
{
2929
Platform plat;
3030
plat.mTitle = title;
@@ -35,20 +35,20 @@ void Platforms::add(const QString &title, cppcheck::Platform::PlatformType platf
3535

3636
void Platforms::init()
3737
{
38-
add(tr("Native"), cppcheck::Platform::Native);
39-
add(tr("Unix 32-bit"), cppcheck::Platform::Unix32);
40-
add(tr("Unix 64-bit"), cppcheck::Platform::Unix64);
41-
add(tr("Windows 32-bit ANSI"), cppcheck::Platform::Win32A);
42-
add(tr("Windows 32-bit Unicode"), cppcheck::Platform::Win32W);
43-
add(tr("Windows 64-bit"), cppcheck::Platform::Win64);
38+
add(tr("Native"), cppcheck::Platform::Type::Native);
39+
add(tr("Unix 32-bit"), cppcheck::Platform::Type::Unix32);
40+
add(tr("Unix 64-bit"), cppcheck::Platform::Type::Unix64);
41+
add(tr("Windows 32-bit ANSI"), cppcheck::Platform::Type::Win32A);
42+
add(tr("Windows 32-bit Unicode"), cppcheck::Platform::Type::Win32W);
43+
add(tr("Windows 64-bit"), cppcheck::Platform::Type::Win64);
4444
}
4545

4646
int Platforms::getCount() const
4747
{
4848
return mPlatforms.count();
4949
}
5050

51-
Platform& Platforms::get(cppcheck::Platform::PlatformType platform)
51+
Platform& Platforms::get(cppcheck::Platform::Type platform)
5252
{
5353
QList<Platform>::iterator iter = mPlatforms.begin();
5454
while (iter != mPlatforms.end()) {

gui/platforms.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class QAction;
3535
*/
3636
struct Platform {
3737
QString mTitle; /**< Text visible in the GUI. */
38-
cppcheck::Platform::PlatformType mType; /**< Type in the core. */
38+
cppcheck::Platform::Type mType; /**< Type in the core. */
3939
QAction *mActMainWindow; /**< Pointer to main window action item. */
4040
};
4141

@@ -47,10 +47,10 @@ class Platforms : public QObject {
4747

4848
public:
4949
explicit Platforms(QObject *parent = nullptr);
50-
void add(const QString &title, cppcheck::Platform::PlatformType platform);
50+
void add(const QString &title, cppcheck::Platform::Type platform);
5151
int getCount() const;
5252
void init();
53-
Platform& get(cppcheck::Platform::PlatformType platform);
53+
Platform& get(cppcheck::Platform::Type platform);
5454

5555
QList<Platform> mPlatforms;
5656
};

gui/projectfile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class ProjectFile : public QObject {
159159

160160
/**
161161
* @brief Get platform.
162-
* @return Current platform. If it ends with .xml then it is a file. Otherwise it must match one of the return values from @sa cppcheck::Platform::platformString() ("win32A", "unix32", ..)
162+
* @return Current platform. If it ends with .xml then it is a file. Otherwise it must match one of the return values from @sa cppcheck::Platform::toString() ("win32A", "unix32", ..)
163163
*/
164164
QString getPlatform() const {
165165
return mPlatform;

gui/projectfiledialog.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ static QStringList getPaths(const QListWidget *list)
6161
}
6262

6363
/** Platforms shown in the platform combobox */
64-
static const cppcheck::Platform::PlatformType builtinPlatforms[] = {
65-
cppcheck::Platform::Native,
66-
cppcheck::Platform::Win32A,
67-
cppcheck::Platform::Win32W,
68-
cppcheck::Platform::Win64,
69-
cppcheck::Platform::Unix32,
70-
cppcheck::Platform::Unix64
64+
static const cppcheck::Platform::Type builtinPlatforms[] = {
65+
cppcheck::Platform::Type::Native,
66+
cppcheck::Platform::Type::Win32A,
67+
cppcheck::Platform::Type::Win32W,
68+
cppcheck::Platform::Type::Win64,
69+
cppcheck::Platform::Type::Unix32,
70+
cppcheck::Platform::Type::Unix64
7171
};
7272

7373
static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]);
@@ -174,7 +174,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
174174

175175
// Platforms..
176176
Platforms platforms;
177-
for (const cppcheck::Platform::PlatformType builtinPlatform : builtinPlatforms)
177+
for (const cppcheck::Platform::Type builtinPlatform : builtinPlatforms)
178178
mUI->mComboBoxPlatform->addItem(platforms.get(builtinPlatform).mTitle);
179179
QStringList platformFiles;
180180
for (QString sp : searchPaths) {
@@ -188,7 +188,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
188188
const QString platformFile = item.fileName();
189189

190190
cppcheck::Platform plat2;
191-
if (!plat2.loadPlatformFile(applicationFilePath.toStdString().c_str(), platformFile.toStdString()))
191+
if (!plat2.loadFromFile(applicationFilePath.toStdString().c_str(), platformFile.toStdString()))
192192
continue;
193193

194194
if (platformFiles.indexOf(platformFile) == -1)
@@ -316,8 +316,8 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
316316
} else {
317317
int i;
318318
for (i = 0; i < numberOfBuiltinPlatforms; ++i) {
319-
const cppcheck::Platform::PlatformType p = builtinPlatforms[i];
320-
if (platform == cppcheck::Platform::platformString(p))
319+
const cppcheck::Platform::Type p = builtinPlatforms[i];
320+
if (platform == cppcheck::Platform::toString(p))
321321
break;
322322
}
323323
if (i < numberOfBuiltinPlatforms)
@@ -416,7 +416,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
416416
else {
417417
const int i = mUI->mComboBoxPlatform->currentIndex();
418418
if (i < numberOfBuiltinPlatforms)
419-
projectFile->setPlatform(cppcheck::Platform::platformString(builtinPlatforms[i]));
419+
projectFile->setPlatform(cppcheck::Platform::toString(builtinPlatforms[i]));
420420
else
421421
projectFile->setPlatform(QString());
422422
}

lib/checkbufferoverrun.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static bool getDimensionsEtc(const Token * const arrayToken, const Settings *set
216216
Dimension dim;
217217
dim.known = value->isKnown();
218218
dim.tok = nullptr;
219-
const int typeSize = array->valueType()->typeSize(*settings, array->valueType()->pointer > 1);
219+
const int typeSize = array->valueType()->typeSize(settings->platform, array->valueType()->pointer > 1);
220220
if (typeSize == 0)
221221
return false;
222222
dim.num = value->intvalue / typeSize;
@@ -564,11 +564,11 @@ ValueFlow::Value CheckBufferOverrun::getBufferSize(const Token *bufTok) const
564564
v.valueType = ValueFlow::Value::ValueType::BUFFER_SIZE;
565565

566566
if (var->isPointerArray())
567-
v.intvalue = dim * mSettings->sizeof_pointer;
567+
v.intvalue = dim * mSettings->platform.sizeof_pointer;
568568
else if (var->isPointer())
569569
return ValueFlow::Value(-1);
570570
else {
571-
const MathLib::bigint typeSize = bufTok->valueType()->typeSize(*mSettings);
571+
const MathLib::bigint typeSize = bufTok->valueType()->typeSize(mSettings->platform);
572572
v.intvalue = dim * typeSize;
573573
}
574574

@@ -885,7 +885,7 @@ bool CheckBufferOverrun::isCtuUnsafeBufferUsage(const Check *check, const Token
885885
const CheckBufferOverrun *c = dynamic_cast<const CheckBufferOverrun *>(check);
886886
if (!c)
887887
return false;
888-
if (!argtok->valueType() || argtok->valueType()->typeSize(*c->mSettings) == 0)
888+
if (!argtok->valueType() || argtok->valueType()->typeSize(c->mSettings->platform) == 0)
889889
return false;
890890
const Token *indexTok = nullptr;
891891
if (type == 1 && Token::Match(argtok, "%name% [") && argtok->astParent() == argtok->next() && !Token::simpleMatch(argtok->linkAt(1), "] ["))
@@ -898,7 +898,7 @@ bool CheckBufferOverrun::isCtuUnsafeBufferUsage(const Check *check, const Token
898898
return false;
899899
if (!indexTok->hasKnownIntValue())
900900
return false;
901-
*offset = indexTok->getKnownIntValue() * argtok->valueType()->typeSize(*c->mSettings);
901+
*offset = indexTok->getKnownIntValue() * argtok->valueType()->typeSize(c->mSettings->platform);
902902
return true;
903903
}
904904

@@ -1051,7 +1051,7 @@ void CheckBufferOverrun::objectIndex()
10511051
continue;
10521052
}
10531053
if (obj->valueType() && var->valueType() && (obj->isCast() || (mTokenizer->isCPP() && isCPPCast(obj)) || obj->valueType()->pointer)) { // allow cast to a different type
1054-
const auto varSize = var->valueType()->typeSize(*mSettings);
1054+
const auto varSize = var->valueType()->typeSize(mSettings->platform);
10551055
if (varSize == 0)
10561056
continue;
10571057
if (obj->valueType()->type != var->valueType()->type) {

lib/checkcondition.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,8 +1860,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
18601860
if (!mSettings->severity.isEnabled(Severity::style))
18611861
return;
18621862

1863-
if (mSettings->platformType == cppcheck::Platform::PlatformType::Native ||
1864-
mSettings->platformType == cppcheck::Platform::PlatformType::Unspecified)
1863+
if (mSettings->platform.type == cppcheck::Platform::Type::Native ||
1864+
mSettings->platform.type == cppcheck::Platform::Type::Unspecified)
18651865
return;
18661866

18671867
const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase();
@@ -1885,19 +1885,19 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
18851885
bits = 1;
18861886
break;
18871887
case ValueType::Type::CHAR:
1888-
bits = mSettings->char_bit;
1888+
bits = mSettings->platform.char_bit;
18891889
break;
18901890
case ValueType::Type::SHORT:
1891-
bits = mSettings->short_bit;
1891+
bits = mSettings->platform.short_bit;
18921892
break;
18931893
case ValueType::Type::INT:
1894-
bits = mSettings->int_bit;
1894+
bits = mSettings->platform.int_bit;
18951895
break;
18961896
case ValueType::Type::LONG:
1897-
bits = mSettings->long_bit;
1897+
bits = mSettings->platform.long_bit;
18981898
break;
18991899
case ValueType::Type::LONGLONG:
1900-
bits = mSettings->long_long_bit;
1900+
bits = mSettings->platform.long_long_bit;
19011901
break;
19021902
default:
19031903
break;
@@ -1910,7 +1910,7 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
19101910
long long typeMaxValue;
19111911
if (typeTok->valueType()->sign != ValueType::Sign::SIGNED)
19121912
typeMaxValue = unsignedTypeMaxValue;
1913-
else if (bits >= mSettings->int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED))
1913+
else if (bits >= mSettings->platform.int_bit && (!valueTok->valueType() || valueTok->valueType()->sign != ValueType::Sign::SIGNED))
19141914
typeMaxValue = unsignedTypeMaxValue;
19151915
else
19161916
typeMaxValue = unsignedTypeMaxValue / 2;

lib/checkfunctions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ void CheckFunctions::memsetInvalid2ndParam()
564564

565565
if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range
566566
const long long int value = MathLib::toLongNumber(secondParamTok->str());
567-
const long long sCharMin = mSettings->signedCharMin();
568-
const long long uCharMax = mSettings->unsignedCharMax();
567+
const long long sCharMin = mSettings->platform.signedCharMin();
568+
const long long uCharMax = mSettings->platform.unsignedCharMax();
569569
if (value < sCharMin || value > uCharMax)
570570
memsetValueOutOfRangeError(secondParamTok, secondParamTok->str());
571571
}

0 commit comments

Comments
 (0)