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
8 changes: 5 additions & 3 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,15 @@ jobs:
./cppcheck $selfcheck_options externals || ec=1
# self check lib/cli
mkdir b1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json cli frontend || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1
# check gui with qt settings
mkdir b2
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b2 -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui || ec=1
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b2 -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB --library=qt --addon=naming.json -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui || ec=1
# self check test and tools
./cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1
./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
# triage
./cppcheck $selfcheck_options $cppcheck_options -DQ_MOC_OUTPUT_REVISION=68 -DQT_CHARTS_LIB --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage || ec=1
exit $ec
8 changes: 5 additions & 3 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,11 @@ jobs:
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options externals || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json cli frontend || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json frontend || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json -Ifrontend cli || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json --enable=internal lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt --addon=naming.json -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli -Ifrontend test/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1
exit $ec
8 changes: 5 additions & 3 deletions .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,11 @@ jobs:
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options externals || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json cli frontend || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json frontend || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json -Ifrontend cli || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json --enable=internal lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt --addon=naming.json -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli -Ifrontend test/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1
exit $ec
8 changes: 5 additions & 3 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ jobs:
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
ec=0
./cmake.output/bin/cppcheck $selfcheck_options externals || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json cli frontend || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json frontend || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json -Ifrontend cli || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json --enable=internal lib || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt --addon=naming.json -Icmake.output/gui -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQT_VERSION=0x060000 -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt --addon=naming.json -Icmake.output/gui -Ifrontend -Igui gui/*.cpp cmake.output/gui/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli -Ifrontend test/*.cpp || ec=1
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
Comment on lines -145 to +150
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

More stuff which was not considered in #7579.

./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -DQ_MOC_OUTPUT_REVISION=69 -DQT_CHARTS_LIB -DQT_MOC_HAS_STRINGDATA --library=qt -Icmake.output/tools/triage -Igui tools/triage/*.cpp cmake.output/tools/triage/*.cpp || ec=1
exit $ec
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ ifndef INCLUDE_FOR_CLI
endif

ifndef INCLUDE_FOR_TEST
INCLUDE_FOR_TEST=-Ilib -Icli -isystem externals/simplecpp -isystem externals/tinyxml2
INCLUDE_FOR_TEST=-Ilib -Ifrontend -Icli -isystem externals/simplecpp -isystem externals/tinyxml2
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I forgot to add this in #7579.

endif

BIN=$(DESTDIR)$(PREFIX)/bin
Expand Down Expand Up @@ -295,6 +295,7 @@ TESTOBJ = test/fixture.o \
test/testexecutor.o \
test/testfilelister.o \
test/testfilesettings.o \
test/testfrontend.o \
test/testfunctions.o \
test/testgarbage.o \
test/testimportproject.o \
Expand Down Expand Up @@ -659,7 +660,7 @@ $(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/addoninfo.h lib/as
$(libcppdir)/vfvalue.o: lib/vfvalue.cpp lib/config.h lib/errortypes.h lib/mathlib.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp

frontend/frontend.o: frontend/frontend.cpp frontend/frontend.h
frontend/frontend.o: frontend/frontend.cpp frontend/frontend.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/utils.h
$(CXX) ${INCLUDE_FOR_FE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ frontend/frontend.cpp

cli/cmdlineparser.o: cli/cmdlineparser.cpp cli/cmdlinelogger.h cli/cmdlineparser.h cli/filelister.h externals/tinyxml2/tinyxml2.h lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/importproject.h lib/library.h lib/mathlib.h lib/path.h lib/pathmatch.h lib/platform.h lib/settings.h lib/standards.h lib/suppressions.h lib/timer.h lib/utils.h lib/xml.h
Expand Down Expand Up @@ -770,6 +771,9 @@ test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/addoninfo.h
test/testfilesettings.o: test/testfilesettings.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfilesettings.cpp

test/testfrontend.o: test/testfrontend.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/filesettings.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/standards.h lib/utils.h test/fixture.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfrontend.cpp

test/testfunctions.o: test/testfunctions.cpp lib/addoninfo.h lib/check.h lib/checkers.h lib/checkfunctions.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/tokenize.h lib/tokenlist.h lib/utils.h test/fixture.h test/helpers.h
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfunctions.cpp

Expand Down
45 changes: 7 additions & 38 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#include "timer.h"
#include "utils.h"

#include "frontend.h"

#include <algorithm>
#include <cassert>
#include <climits>
Expand Down Expand Up @@ -221,40 +223,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])

mFileSettings.clear();

if (mSettings.enforcedLang != Standards::Language::None)
{
// apply enforced language
for (auto& fs : fileSettings)
{
if (mSettings.library.markupFile(fs.filename()))
continue;
fs.file.setLang(mSettings.enforcedLang);
}
}
else
{
// identify files
for (auto& fs : fileSettings)
{
if (mSettings.library.markupFile(fs.filename()))
continue;
assert(fs.file.lang() == Standards::Language::None);
bool header = false;
fs.file.setLang(Path::identify(fs.filename(), mSettings.cppHeaderProbe, &header));
// unknown extensions default to C++
if (!header && fs.file.lang() == Standards::Language::None)
fs.file.setLang(Standards::Language::CPP);
}
}

// enforce the language since markup files are special and do not adhere to the enforced language
for (auto& fs : fileSettings)
{
if (mSettings.library.markupFile(fs.filename())) {
assert(fs.file.lang() == Standards::Language::None);
fs.file.setLang(Standards::Language::C);
}
}
frontend::applyLang(fileSettings, mSettings, mEnforcedLang);

// sort the markup last
std::copy_if(fileSettings.cbegin(), fileSettings.cend(), std::back_inserter(mFileSettings), [&](const FileSettings &fs) {
Expand Down Expand Up @@ -324,14 +293,14 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
files = std::move(filesResolved);
}

if (mSettings.enforcedLang != Standards::Language::None)
if (mEnforcedLang != Standards::Language::None)
{
// apply enforced language
for (auto& f : files)
{
if (mSettings.library.markupFile(f.path()))
continue;
f.setLang(mSettings.enforcedLang);
f.setLang(mEnforcedLang);
}
}
else
Expand Down Expand Up @@ -985,9 +954,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
}

if (str == "c")
mSettings.enforcedLang = Standards::Language::C;
mEnforcedLang = Standards::Language::C;
else if (str == "c++")
mSettings.enforcedLang = Standards::Language::CPP;
mEnforcedLang = Standards::Language::CPP;
else {
mLogger.printError("unknown language '" + str + "' enforced.");
return Result::Fail;
Expand Down
6 changes: 4 additions & 2 deletions cli/cmdlineparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "cmdlinelogger.h"
#include "filesettings.h"
#include "standards.h"
#include "utils.h"

class Settings;
Expand All @@ -46,6 +47,7 @@ class Library;
* class internal options.
*/
class CmdLineParser {
friend class TestCmdlineParser;
public:
/**
* The constructor.
Expand Down Expand Up @@ -175,8 +177,8 @@ class CmdLineParser {
Settings &mSettings;
Suppressions &mSuppressions;
bool mAnalyzeAllVsConfigsSetOnCmdLine = false;

friend class TestCmdlineParser;
/** @brief Name of the language that is enforced. Empty per default. */
Standards::Language mEnforcedLang{Standards::Language::None};
};

/// @}
Expand Down
48 changes: 46 additions & 2 deletions frontend/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,49 @@

#include "frontend.h"

namespace frontend
{}
#include "filesettings.h"
#include "library.h"
#include "path.h"
#include "settings.h"

#include <cassert>

namespace frontend {
void applyLang(std::list<FileSettings>& fileSettings, const Settings& settings, Standards::Language enforcedLang)
{
if (enforcedLang != Standards::Language::None)
{
// apply enforced language
for (auto& fs : fileSettings)
{
if (settings.library.markupFile(fs.filename()))
continue;
fs.file.setLang(enforcedLang);
}
}
else
{
// identify files
for (auto& fs : fileSettings)
{
if (settings.library.markupFile(fs.filename()))
continue;
assert(fs.file.lang() == Standards::Language::None);
bool header = false;
fs.file.setLang(Path::identify(fs.filename(), settings.cppHeaderProbe, &header));
// unknown extensions default to C++
if (!header && fs.file.lang() == Standards::Language::None)
fs.file.setLang(Standards::Language::CPP);
}
}

// enforce the language since markup files are special and do not adhere to the enforced language
for (auto& fs : fileSettings)
{
if (settings.library.markupFile(fs.filename())) {
assert(fs.file.lang() == Standards::Language::None);
fs.file.setLang(Standards::Language::C);
}
}
}
}
14 changes: 13 additions & 1 deletion frontend/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,19 @@
#ifndef FRONTEND_H
#define FRONTEND_H

#include "standards.h"

#include <list>

struct FileSettings;
class Settings;

namespace frontend
{}
{
/**
Applies the enforced language as all as identifying remaining files - also taking markup files into consideration.
*/
void applyLang(std::list<FileSettings> &fileSettings, const Settings &settings, Standards::Language enforcedLang);
}

#endif // FRONTEND_H
2 changes: 2 additions & 0 deletions gui/checkthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void CheckThread::run()
qDebug() << "Whole program analysis";
std::list<FileWithDetails> files2;
std::transform(mFiles.cbegin(), mFiles.cend(), std::back_inserter(files2), [&](const QString& file) {
// TODO: apply enforcedLanguage
return FileWithDetails{file.toStdString(), Path::identify(file.toStdString(), mSettings.cppHeaderProbe), 0};
});
cppcheck.analyseWholeProgram(mSettings.buildDir, files2, {}, ctuInfo);
Expand All @@ -151,6 +152,7 @@ void CheckThread::run()
return;
}

// TODO: apply enforcedLanguage
const FileWithDetails* file = nullptr;
mResult.getNextFile(file);
while (file && mState == Running) {
Expand Down
12 changes: 9 additions & 3 deletions gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@

#include "ui_mainwindow.h"

#include "frontend.h"

#include <algorithm>
#include <iterator>
#include <list>
Expand Down Expand Up @@ -604,6 +606,10 @@ void MainWindow::doAnalyzeProject(ImportProject p, const bool checkLibrary, cons
mThread->setClangIncludePaths(clangHeaders.split(";"));
mThread->setSuppressions(mProjectFile->getSuppressions());
}

const Standards::Language enforcedLang = static_cast<Standards::Language>(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt());
frontend::applyLang(p.fileSettings, checkSettings, enforcedLang);

mThread->setProject(p);
mThread->check(checkSettings, supprs);
mUI->mResults->setCheckSettings(checkSettings);
Expand Down Expand Up @@ -703,6 +709,7 @@ void MainWindow::analyzeCode(const QString& code, const QString& filename)
checkLockDownUI();
clearResults();
mUI->mResults->checkingStarted(1);
// TODO: apply enforcedLanguage
cppcheck.check(FileWithDetails(filename.toStdString(), Path::identify(filename.toStdString(), false), 0), code.toStdString());
analysisDone();

Expand Down Expand Up @@ -797,7 +804,7 @@ void MainWindow::analyzeFiles()
p.ignoreOtherConfigs(cfg.toStdString());
}

doAnalyzeProject(p);
doAnalyzeProject(p); // TODO: avoid copy
return;
}

Expand Down Expand Up @@ -1208,7 +1215,6 @@ bool MainWindow::getCppcheckSettings(Settings& settings, Suppressions& supprs)
settings.platform.set(static_cast<Platform::Type>(mSettings->value(SETTINGS_CHECKED_PLATFORM, 0).toInt()));
settings.standards.setCPP(mSettings->value(SETTINGS_STD_CPP, QString()).toString().toStdString());
settings.standards.setC(mSettings->value(SETTINGS_STD_C, QString()).toString().toStdString());
settings.enforcedLang = static_cast<Standards::Language>(mSettings->value(SETTINGS_ENFORCED_LANGUAGE, 0).toInt());

settings.jobs = std::max(settings.jobs, 1u);

Expand Down Expand Up @@ -1960,7 +1966,7 @@ void MainWindow::analyzeProject(const ProjectFile *projectFile, const QStringLis
msg.exec();
return;
}
doAnalyzeProject(p, checkLibrary, checkConfiguration);
doAnalyzeProject(p, checkLibrary, checkConfiguration); // TODO: avoid copy
return;
}

Expand Down
3 changes: 0 additions & 3 deletions lib/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ class CPPCHECKLIB WARN_UNUSED Settings {
/** @brief Do not filter duplicated errors. */
bool emitDuplicates{};

/** @brief Name of the language that is enforced. Empty per default. */
Standards::Language enforcedLang{};

#if defined(USE_WINDOWS_SEH) || defined(USE_UNIX_SIGNAL_HANDLING)
/** @brief Is --exception-handling given */
bool exceptionHandling{};
Expand Down
Loading
Loading