Skip to content
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
4 changes: 2 additions & 2 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
// these are loaded via external files and thus have Settings::PlatformFile set instead.
// override the type so they behave like the regular platforms.
if (platform == "unix32-unsigned")
mSettings.platform.type = cppcheck::Platform::Type::Unix32;
mSettings.platform.type = Platform::Type::Unix32;
else if (platform == "unix64-unsigned")
mSettings.platform.type = cppcheck::Platform::Type::Unix64;
mSettings.platform.type = Platform::Type::Unix64;
}

// Write results in results.plist
Expand Down
22 changes: 11 additions & 11 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
mUI->mActionEditProjectFile->setEnabled(mProjectFile != nullptr);

for (int i = 0; i < mPlatforms.getCount(); i++) {
Platform platform = mPlatforms.mPlatforms[i];
PlatformData platform = mPlatforms.mPlatforms[i];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not your code but platform should probably be a reference. the assignment at line 249 looks strange.

QAction *action = new QAction(this);
platform.mActMainWindow = action;
mPlatforms.mPlatforms[i] = platform;
Expand Down Expand Up @@ -274,11 +274,11 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
// For other platforms default to unspecified/default which means the
// platform Cppcheck GUI was compiled on.
#if defined(_WIN32)
const cppcheck::Platform::Type defaultPlatform = cppcheck::Platform::Type::Win32W;
const Platform::Type defaultPlatform = Platform::Type::Win32W;
#else
const cppcheck::Platform::Type defaultPlatform = cppcheck::Platform::Type::Unspecified;
const Platform::Type defaultPlatform = Platform::Type::Unspecified;
#endif
Platform &platform = mPlatforms.get((cppcheck::Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
PlatformData &platform = mPlatforms.get((Platform::Type)mSettings->value(SETTINGS_CHECKED_PLATFORM, defaultPlatform).toInt());
platform.mActMainWindow->setChecked(true);

mNetworkAccessManager = new QNetworkAccessManager(this);
Expand Down Expand Up @@ -494,7 +494,7 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
p.ignorePaths(v);

if (!mProjectFile->getAnalyzeAllVsConfigs()) {
const cppcheck::Platform::Type platform = (cppcheck::Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
const Platform::Type platform = (Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt();
std::vector<std::string> configurations;
const QStringList configs = mProjectFile->getVsConfigurations();
std::transform(configs.cbegin(), configs.cend(), std::back_inserter(configurations), [](const QString& e) {
Expand Down Expand Up @@ -967,9 +967,9 @@ Settings MainWindow::getCppcheckSettings()
const QString applicationFilePath = QCoreApplication::applicationFilePath();
result.platform.loadFromFile(applicationFilePath.toStdString().c_str(), platform.toStdString());
} else {
for (int i = cppcheck::Platform::Type::Native; i <= cppcheck::Platform::Type::Unix64; i++) {
const cppcheck::Platform::Type p = (cppcheck::Platform::Type)i;
if (platform == cppcheck::Platform::toString(p)) {
for (int i = Platform::Type::Native; i <= Platform::Type::Unix64; i++) {
const Platform::Type p = (Platform::Type)i;
if (platform == Platform::toString(p)) {
result.platform.set(p);
break;
}
Expand Down Expand Up @@ -1060,8 +1060,8 @@ Settings MainWindow::getCppcheckSettings()
result.jobs = mSettings->value(SETTINGS_CHECK_THREADS, 1).toInt();
result.inlineSuppressions = mSettings->value(SETTINGS_INLINE_SUPPRESSIONS, false).toBool();
result.certainty.setEnabled(Certainty::inconclusive, mSettings->value(SETTINGS_INCONCLUSIVE_ERRORS, false).toBool());
if (!mProjectFile || result.platform.type == cppcheck::Platform::Type::Unspecified)
result.platform.set((cppcheck::Platform::Type) mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt());
if (!mProjectFile || result.platform.type == Platform::Type::Unspecified)
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();
Expand Down Expand Up @@ -1987,7 +1987,7 @@ void MainWindow::selectPlatform()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
const cppcheck::Platform::Type platform = (cppcheck::Platform::Type) action->data().toInt();
const Platform::Type platform = (Platform::Type) action->data().toInt();
mSettings->setValue(SETTINGS_CHECKED_PLATFORM, platform);
}
}
Expand Down
20 changes: 10 additions & 10 deletions gui/platforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ Platforms::Platforms(QObject *parent)
init();
}

void Platforms::add(const QString &title, cppcheck::Platform::Type platform)
void Platforms::add(const QString &title, Platform::Type platform)
{
Platform plat;
PlatformData plat;
plat.mTitle = title;
plat.mType = platform;
plat.mActMainWindow = nullptr;
Expand All @@ -35,22 +35,22 @@ void Platforms::add(const QString &title, cppcheck::Platform::Type platform)

void Platforms::init()
{
add(tr("Native"), cppcheck::Platform::Type::Native);
add(tr("Unix 32-bit"), cppcheck::Platform::Type::Unix32);
add(tr("Unix 64-bit"), cppcheck::Platform::Type::Unix64);
add(tr("Windows 32-bit ANSI"), cppcheck::Platform::Type::Win32A);
add(tr("Windows 32-bit Unicode"), cppcheck::Platform::Type::Win32W);
add(tr("Windows 64-bit"), cppcheck::Platform::Type::Win64);
add(tr("Native"), Platform::Type::Native);
add(tr("Unix 32-bit"), Platform::Type::Unix32);
add(tr("Unix 64-bit"), Platform::Type::Unix64);
add(tr("Windows 32-bit ANSI"), Platform::Type::Win32A);
add(tr("Windows 32-bit Unicode"), Platform::Type::Win32W);
add(tr("Windows 64-bit"), Platform::Type::Win64);
}

int Platforms::getCount() const
{
return mPlatforms.count();
}

Platform& Platforms::get(cppcheck::Platform::Type platform)
PlatformData& Platforms::get(Platform::Type platform)
{
QList<Platform>::iterator iter = mPlatforms.begin();
QList<PlatformData>::iterator iter = mPlatforms.begin();
while (iter != mPlatforms.end()) {
if ((*iter).mType == platform) {
return *iter;
Expand Down
10 changes: 5 additions & 5 deletions gui/platforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class QAction;
/**
* @brief Checked platform GUI-data.
*/
struct Platform {
struct PlatformData {
QString mTitle; /**< Text visible in the GUI. */
cppcheck::Platform::Type mType; /**< Type in the core. */
Platform::Type mType; /**< Type in the core. */
QAction *mActMainWindow; /**< Pointer to main window action item. */
};

Expand All @@ -47,12 +47,12 @@ class Platforms : public QObject {

public:
explicit Platforms(QObject *parent = nullptr);
void add(const QString &title, cppcheck::Platform::Type platform);
void add(const QString &title, Platform::Type platform);
int getCount() const;
void init();
Platform& get(cppcheck::Platform::Type platform);
PlatformData& get(Platform::Type platform);

QList<Platform> mPlatforms;
QList<PlatformData> mPlatforms;
};

/// @}
Expand Down
24 changes: 12 additions & 12 deletions gui/projectfiledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ static QStringList getPaths(const QListWidget *list)
}

/** Platforms shown in the platform combobox */
static const cppcheck::Platform::Type builtinPlatforms[] = {
cppcheck::Platform::Type::Native,
cppcheck::Platform::Type::Win32A,
cppcheck::Platform::Type::Win32W,
cppcheck::Platform::Type::Win64,
cppcheck::Platform::Type::Unix32,
cppcheck::Platform::Type::Unix64
static const Platform::Type builtinPlatforms[] = {
Platform::Type::Native,
Platform::Type::Win32A,
Platform::Type::Win32W,
Platform::Type::Win64,
Platform::Type::Unix32,
Platform::Type::Unix64
};

static const int numberOfBuiltinPlatforms = sizeof(builtinPlatforms) / sizeof(builtinPlatforms[0]);
Expand Down Expand Up @@ -190,7 +190,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi

// Platforms..
Platforms platforms;
for (const cppcheck::Platform::Type builtinPlatform : builtinPlatforms)
for (const Platform::Type builtinPlatform : builtinPlatforms)
mUI->mComboBoxPlatform->addItem(platforms.get(builtinPlatform).mTitle);
QStringList platformFiles;
for (QString sp : searchPaths) {
Expand All @@ -203,7 +203,7 @@ ProjectFileDialog::ProjectFileDialog(ProjectFile *projectFile, bool premium, QWi
for (const QFileInfo& item : dir.entryInfoList()) {
const QString platformFile = item.fileName();

cppcheck::Platform plat2;
Platform plat2;
if (!plat2.loadFromFile(applicationFilePath.toStdString().c_str(), platformFile.toStdString()))
continue;

Expand Down Expand Up @@ -336,8 +336,8 @@ void ProjectFileDialog::loadFromProjectFile(const ProjectFile *projectFile)
} else {
int i;
for (i = 0; i < numberOfBuiltinPlatforms; ++i) {
const cppcheck::Platform::Type p = builtinPlatforms[i];
if (platform == cppcheck::Platform::toString(p))
const Platform::Type p = builtinPlatforms[i];
if (platform == Platform::toString(p))
break;
}
if (i < numberOfBuiltinPlatforms)
Expand Down Expand Up @@ -445,7 +445,7 @@ void ProjectFileDialog::saveToProjectFile(ProjectFile *projectFile) const
else {
const int i = mUI->mComboBoxPlatform->currentIndex();
if (i>=0 && i < numberOfBuiltinPlatforms)
projectFile->setPlatform(cppcheck::Platform::toString(builtinPlatforms[i]));
projectFile->setPlatform(Platform::toString(builtinPlatforms[i]));
else
projectFile->setPlatform(QString());
}
Expand Down
2 changes: 1 addition & 1 deletion gui/test/projectfile/testprojectfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const char Settings::SafeChecks::XmlExternalFunctions[] = "external-functions";
const char Settings::SafeChecks::XmlInternalFunctions[] = "internal-functions";
const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";
Settings::Settings() : maxCtuDepth(10) {}
cppcheck::Platform::Platform() = default;
Platform::Platform() = default;
bool ImportProject::sourceFileExists(const std::string & /*file*/) {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/checkcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1912,8 +1912,8 @@ void CheckCondition::checkCompareValueOutOfTypeRange()
if (!mSettings->severity.isEnabled(Severity::style))
return;

if (mSettings->platform.type == cppcheck::Platform::Type::Native ||
mSettings->platform.type == cppcheck::Platform::Type::Unspecified)
if (mSettings->platform.type == Platform::Type::Native ||
mSettings->platform.type == Platform::Type::Unspecified)
return;

logChecker("CheckCondition::checkCompareValueOutOfTypeRange"); // style,platform
Expand Down
6 changes: 3 additions & 3 deletions lib/checktype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static const CWE CWE190(190U); // Integer Overflow or Wraparound
void CheckType::checkTooBigBitwiseShift()
{
// unknown sizeof(int) => can't run this checker
if (mSettings->platform.type == cppcheck::Platform::Type::Unspecified)
if (mSettings->platform.type == Platform::Type::Unspecified)
return;

logChecker("CheckType::checkTooBigBitwiseShift"); // platform
Expand Down Expand Up @@ -167,7 +167,7 @@ void CheckType::tooBigSignedBitwiseShiftError(const Token *tok, int lhsbits, con
void CheckType::checkIntegerOverflow()
{
// unknown sizeof(int) => can't run this checker
if (mSettings->platform.type == cppcheck::Platform::Type::Unspecified || mSettings->platform.int_bit >= MathLib::bigint_bits)
if (mSettings->platform.type == Platform::Type::Unspecified || mSettings->platform.int_bit >= MathLib::bigint_bits)
return;

logChecker("CheckType::checkIntegerOverflow"); // platform
Expand Down Expand Up @@ -476,7 +476,7 @@ void CheckType::checkFloatToIntegerOverflow(const Token *tok, const ValueType *v
floatToIntegerOverflowError(tok, f);
else if ((-f.floatValue) > std::exp2(mSettings->platform.long_long_bit - 1))
floatToIntegerOverflowError(tok, f);
else if (mSettings->platform.type != cppcheck::Platform::Type::Unspecified) {
else if (mSettings->platform.type != Platform::Type::Unspecified) {
int bits = 0;
if (vtint->type == ValueType::Type::CHAR)
bits = mSettings->platform.char_bit;
Expand Down
2 changes: 1 addition & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ unsigned int CppCheck::check(const ImportProject::FileSettings &fs)
temp.mSettings.standards.setCPP(fs.standard);
else if (!fs.standard.empty())
temp.mSettings.standards.setC(fs.standard);
if (fs.platformType != cppcheck::Platform::Type::Unspecified)
if (fs.platformType != Platform::Type::Unspecified)
temp.mSettings.platform.set(fs.platformType);
if (mSettings.clang) {
temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend());
Expand Down
16 changes: 8 additions & 8 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,9 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
fs.useMfc = useOfMfc;
fs.defines = "_WIN32=1";
if (p.platform == ProjectConfiguration::Win32)
fs.platformType = cppcheck::Platform::Type::Win32W;
fs.platformType = Platform::Type::Win32W;
else if (p.platform == ProjectConfiguration::x64) {
fs.platformType = cppcheck::Platform::Type::Win64;
fs.platformType = Platform::Type::Win64;
fs.defines += ";_WIN64=1";
}
std::string additionalIncludePaths;
Expand Down Expand Up @@ -1264,7 +1264,7 @@ bool ImportProject::importCppcheckGuiProject(std::istream &istr, Settings *setti
return true;
}

void ImportProject::selectOneVsConfig(cppcheck::Platform::Type platform)
void ImportProject::selectOneVsConfig(Platform::Type platform)
{
std::set<std::string> filenames;
for (std::list<ImportProject::FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {
Expand All @@ -1276,9 +1276,9 @@ void ImportProject::selectOneVsConfig(cppcheck::Platform::Type platform)
bool remove = false;
if (!startsWith(fs.cfg,"Debug"))
remove = true;
if (platform == cppcheck::Platform::Type::Win64 && fs.platformType != platform)
if (platform == Platform::Type::Win64 && fs.platformType != platform)
remove = true;
else if ((platform == cppcheck::Platform::Type::Win32A || platform == cppcheck::Platform::Type::Win32W) && fs.platformType == cppcheck::Platform::Type::Win64)
else if ((platform == Platform::Type::Win32A || platform == Platform::Type::Win32W) && fs.platformType == Platform::Type::Win64)
remove = true;
else if (filenames.find(fs.filename) != filenames.end())
remove = true;
Expand All @@ -1291,7 +1291,7 @@ void ImportProject::selectOneVsConfig(cppcheck::Platform::Type platform)
}
}

void ImportProject::selectVsConfigurations(cppcheck::Platform::Type platform, const std::vector<std::string> &configurations)
void ImportProject::selectVsConfigurations(Platform::Type platform, const std::vector<std::string> &configurations)
{
for (std::list<ImportProject::FileSettings>::iterator it = fileSettings.begin(); it != fileSettings.end();) {
if (it->cfg.empty()) {
Expand All @@ -1303,9 +1303,9 @@ void ImportProject::selectVsConfigurations(cppcheck::Platform::Type platform, co
bool remove = false;
if (std::find(configurations.begin(), configurations.end(), config) == configurations.end())
remove = true;
if (platform == cppcheck::Platform::Type::Win64 && fs.platformType != platform)
if (platform == Platform::Type::Win64 && fs.platformType != platform)
remove = true;
else if ((platform == cppcheck::Platform::Type::Win32A || platform == cppcheck::Platform::Type::Win32W) && fs.platformType == cppcheck::Platform::Type::Win64)
else if ((platform == Platform::Type::Win32A || platform == Platform::Type::Win32W) && fs.platformType == Platform::Type::Win64)
remove = true;
if (remove) {
it = fileSettings.erase(it);
Expand Down
6 changes: 3 additions & 3 deletions lib/importproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class CPPCHECKLIB ImportProject {
std::list<std::string> includePaths;
std::list<std::string> systemIncludePaths;
std::string standard;
cppcheck::Platform::Type platformType = cppcheck::Platform::Type::Unspecified;
Platform::Type platformType = Platform::Type::Unspecified;
bool msc{};
bool useMfc{};

Expand All @@ -90,8 +90,8 @@ class CPPCHECKLIB ImportProject {
ImportProject(const ImportProject&) = default;
ImportProject& operator=(const ImportProject&) = default;

void selectOneVsConfig(cppcheck::Platform::Type platform);
void selectVsConfigurations(cppcheck::Platform::Type platform, const std::vector<std::string> &configurations);
void selectOneVsConfig(Platform::Type platform);
void selectVsConfigurations(Platform::Type platform, const std::vector<std::string> &configurations);

std::list<std::string> getVSConfigs();

Expand Down
10 changes: 5 additions & 5 deletions lib/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@

#include <tinyxml2.h>

cppcheck::Platform::Platform()
Platform::Platform()
{
set(Type::Native);
}


bool cppcheck::Platform::set(Type t)
bool Platform::set(Type t)
{
switch (t) {
case Type::Unspecified: // unknown type sizes (sizes etc are set but are not known)
Expand Down Expand Up @@ -150,7 +150,7 @@ bool cppcheck::Platform::set(Type t)
return false;
}

bool cppcheck::Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
bool Platform::set(const std::string& platformstr, std::string& errstr, const std::vector<std::string>& paths, bool verbose)
{
if (platformstr == "win32A")
set(Type::Win32A);
Expand Down Expand Up @@ -189,7 +189,7 @@ bool cppcheck::Platform::set(const std::string& platformstr, std::string& errstr
return true;
}

bool cppcheck::Platform::loadFromFile(const char exename[], const std::string &filename, bool verbose)
bool Platform::loadFromFile(const char exename[], const std::string &filename, bool verbose)
{
// TODO: only append .xml if missing
// TODO: use native separators
Expand Down Expand Up @@ -240,7 +240,7 @@ static unsigned int xmlTextAsUInt(const tinyxml2::XMLElement* node, bool& error)
return retval;
}

bool cppcheck::Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
bool Platform::loadFromXmlDocument(const tinyxml2::XMLDocument *doc)
{
const tinyxml2::XMLElement * const rootnode = doc->FirstChildElement();

Expand Down
Loading