Skip to content

Commit 1af769e

Browse files
authored
fixed #13909 / refs #13914 - some (enforced) language handling fixes for the GUI (danmar#7570)
1 parent d071066 commit 1af769e

File tree

16 files changed

+205
-68
lines changed

16 files changed

+205
-68
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,13 +523,15 @@ jobs:
523523
./cppcheck $selfcheck_options externals || ec=1
524524
# self check lib/cli
525525
mkdir b1
526-
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json cli frontend || ec=1
526+
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json frontend || ec=1
527+
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json -Ifrontend cli || ec=1
527528
./cppcheck $selfcheck_options $cppcheck_options --cppcheck-build-dir=b1 --addon=naming.json --enable=internal lib || ec=1
528529
# check gui with qt settings
529530
mkdir b2
530-
./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
531+
./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
531532
# self check test and tools
532-
./cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
533+
./cppcheck $selfcheck_options $cppcheck_options -Ifrontend -Icli test/*.cpp || ec=1
534+
./cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
533535
# triage
534536
./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
535537
exit $ec

.github/workflows/asan.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ jobs:
145145
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
146146
ec=0
147147
./cmake.output/bin/cppcheck $selfcheck_options externals || ec=1
148-
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json cli frontend || ec=1
148+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json frontend || ec=1
149+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json -Ifrontend cli || ec=1
149150
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json --enable=internal lib || ec=1
150-
./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
151-
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
151+
./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
152+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli -Ifrontend test/*.cpp || ec=1
153+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
152154
./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
153155
exit $ec

.github/workflows/tsan.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,11 @@ jobs:
148148
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
149149
ec=0
150150
./cmake.output/bin/cppcheck $selfcheck_options externals || ec=1
151-
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json cli frontend || ec=1
151+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json frontend || ec=1
152+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json -Ifrontend cli || ec=1
152153
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json --enable=internal lib || ec=1
153-
./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
154-
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
154+
./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
155+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli -Ifrontend test/*.cpp || ec=1
156+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
155157
./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
156158
exit $ec

.github/workflows/ubsan.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ jobs:
142142
cppcheck_options="-D__CPPCHECK__ -DCHECK_INTERNAL -DHAVE_RULES --library=cppcheck-lib -Ilib -Iexternals/simplecpp/ -Iexternals/tinyxml2"
143143
ec=0
144144
./cmake.output/bin/cppcheck $selfcheck_options externals || ec=1
145-
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json cli frontend || ec=1
145+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json frontend || ec=1
146+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json -Ifrontend cli || ec=1
146147
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options --addon=naming.json --enable=internal lib || ec=1
147-
./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
148-
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli test/*.cpp tools/dmake/*.cpp || ec=1
148+
./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
149+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli -Ifrontend test/*.cpp || ec=1
150+
./cmake.output/bin/cppcheck $selfcheck_options $cppcheck_options -Icli tools/dmake/*.cpp || ec=1
149151
./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
150152
exit $ec

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ ifndef INCLUDE_FOR_CLI
171171
endif
172172

173173
ifndef INCLUDE_FOR_TEST
174-
INCLUDE_FOR_TEST=-Ilib -Icli -isystem externals/simplecpp -isystem externals/tinyxml2
174+
INCLUDE_FOR_TEST=-Ilib -Ifrontend -Icli -isystem externals/simplecpp -isystem externals/tinyxml2
175175
endif
176176

177177
BIN=$(DESTDIR)$(PREFIX)/bin
@@ -295,6 +295,7 @@ TESTOBJ = test/fixture.o \
295295
test/testexecutor.o \
296296
test/testfilelister.o \
297297
test/testfilesettings.o \
298+
test/testfrontend.o \
298299
test/testfunctions.o \
299300
test/testgarbage.o \
300301
test/testimportproject.o \
@@ -659,7 +660,7 @@ $(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/addoninfo.h lib/as
659660
$(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
660661
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp
661662

662-
frontend/frontend.o: frontend/frontend.cpp frontend/frontend.h
663+
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
663664
$(CXX) ${INCLUDE_FOR_FE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ frontend/frontend.cpp
664665

665666
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
@@ -770,6 +771,9 @@ test/testfilelister.o: test/testfilelister.cpp cli/filelister.h lib/addoninfo.h
770771
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
771772
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfilesettings.cpp
772773

774+
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
775+
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfrontend.cpp
776+
773777
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
774778
$(CXX) ${INCLUDE_FOR_TEST} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ test/testfunctions.cpp
775779

cli/cmdlineparser.cpp

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
#include "timer.h"
4040
#include "utils.h"
4141

42+
#include "frontend.h"
43+
4244
#include <algorithm>
4345
#include <cassert>
4446
#include <climits>
@@ -221,40 +223,7 @@ bool CmdLineParser::fillSettingsFromArgs(int argc, const char* const argv[])
221223

222224
mFileSettings.clear();
223225

224-
if (mSettings.enforcedLang != Standards::Language::None)
225-
{
226-
// apply enforced language
227-
for (auto& fs : fileSettings)
228-
{
229-
if (mSettings.library.markupFile(fs.filename()))
230-
continue;
231-
fs.file.setLang(mSettings.enforcedLang);
232-
}
233-
}
234-
else
235-
{
236-
// identify files
237-
for (auto& fs : fileSettings)
238-
{
239-
if (mSettings.library.markupFile(fs.filename()))
240-
continue;
241-
assert(fs.file.lang() == Standards::Language::None);
242-
bool header = false;
243-
fs.file.setLang(Path::identify(fs.filename(), mSettings.cppHeaderProbe, &header));
244-
// unknown extensions default to C++
245-
if (!header && fs.file.lang() == Standards::Language::None)
246-
fs.file.setLang(Standards::Language::CPP);
247-
}
248-
}
249-
250-
// enforce the language since markup files are special and do not adhere to the enforced language
251-
for (auto& fs : fileSettings)
252-
{
253-
if (mSettings.library.markupFile(fs.filename())) {
254-
assert(fs.file.lang() == Standards::Language::None);
255-
fs.file.setLang(Standards::Language::C);
256-
}
257-
}
226+
frontend::applyLang(fileSettings, mSettings, mEnforcedLang);
258227

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

327-
if (mSettings.enforcedLang != Standards::Language::None)
296+
if (mEnforcedLang != Standards::Language::None)
328297
{
329298
// apply enforced language
330299
for (auto& f : files)
331300
{
332301
if (mSettings.library.markupFile(f.path()))
333302
continue;
334-
f.setLang(mSettings.enforcedLang);
303+
f.setLang(mEnforcedLang);
335304
}
336305
}
337306
else
@@ -985,9 +954,9 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
985954
}
986955

987956
if (str == "c")
988-
mSettings.enforcedLang = Standards::Language::C;
957+
mEnforcedLang = Standards::Language::C;
989958
else if (str == "c++")
990-
mSettings.enforcedLang = Standards::Language::CPP;
959+
mEnforcedLang = Standards::Language::CPP;
991960
else {
992961
mLogger.printError("unknown language '" + str + "' enforced.");
993962
return Result::Fail;

cli/cmdlineparser.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "cmdlinelogger.h"
2929
#include "filesettings.h"
30+
#include "standards.h"
3031
#include "utils.h"
3132

3233
class Settings;
@@ -46,6 +47,7 @@ class Library;
4647
* class internal options.
4748
*/
4849
class CmdLineParser {
50+
friend class TestCmdlineParser;
4951
public:
5052
/**
5153
* The constructor.
@@ -175,8 +177,8 @@ class CmdLineParser {
175177
Settings &mSettings;
176178
Suppressions &mSuppressions;
177179
bool mAnalyzeAllVsConfigsSetOnCmdLine = false;
178-
179-
friend class TestCmdlineParser;
180+
/** @brief Name of the language that is enforced. Empty per default. */
181+
Standards::Language mEnforcedLang{Standards::Language::None};
180182
};
181183

182184
/// @}

frontend/frontend.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,49 @@
1818

1919
#include "frontend.h"
2020

21-
namespace frontend
22-
{}
21+
#include "filesettings.h"
22+
#include "library.h"
23+
#include "path.h"
24+
#include "settings.h"
25+
26+
#include <cassert>
27+
28+
namespace frontend {
29+
void applyLang(std::list<FileSettings>& fileSettings, const Settings& settings, Standards::Language enforcedLang)
30+
{
31+
if (enforcedLang != Standards::Language::None)
32+
{
33+
// apply enforced language
34+
for (auto& fs : fileSettings)
35+
{
36+
if (settings.library.markupFile(fs.filename()))
37+
continue;
38+
fs.file.setLang(enforcedLang);
39+
}
40+
}
41+
else
42+
{
43+
// identify files
44+
for (auto& fs : fileSettings)
45+
{
46+
if (settings.library.markupFile(fs.filename()))
47+
continue;
48+
assert(fs.file.lang() == Standards::Language::None);
49+
bool header = false;
50+
fs.file.setLang(Path::identify(fs.filename(), settings.cppHeaderProbe, &header));
51+
// unknown extensions default to C++
52+
if (!header && fs.file.lang() == Standards::Language::None)
53+
fs.file.setLang(Standards::Language::CPP);
54+
}
55+
}
56+
57+
// enforce the language since markup files are special and do not adhere to the enforced language
58+
for (auto& fs : fileSettings)
59+
{
60+
if (settings.library.markupFile(fs.filename())) {
61+
assert(fs.file.lang() == Standards::Language::None);
62+
fs.file.setLang(Standards::Language::C);
63+
}
64+
}
65+
}
66+
}

frontend/frontend.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@
1919
#ifndef FRONTEND_H
2020
#define FRONTEND_H
2121

22+
#include "standards.h"
23+
24+
#include <list>
25+
26+
struct FileSettings;
27+
class Settings;
28+
2229
namespace frontend
23-
{}
30+
{
31+
/**
32+
Applies the enforced language as all as identifying remaining files - also taking markup files into consideration.
33+
*/
34+
void applyLang(std::list<FileSettings> &fileSettings, const Settings &settings, Standards::Language enforcedLang);
35+
}
2436

2537
#endif // FRONTEND_H

gui/checkthread.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void CheckThread::run()
143143
qDebug() << "Whole program analysis";
144144
std::list<FileWithDetails> files2;
145145
std::transform(mFiles.cbegin(), mFiles.cend(), std::back_inserter(files2), [&](const QString& file) {
146+
// TODO: apply enforcedLanguage
146147
return FileWithDetails{file.toStdString(), Path::identify(file.toStdString(), mSettings.cppHeaderProbe), 0};
147148
});
148149
cppcheck.analyseWholeProgram(mSettings.buildDir, files2, {}, ctuInfo);
@@ -151,6 +152,7 @@ void CheckThread::run()
151152
return;
152153
}
153154

155+
// TODO: apply enforcedLanguage
154156
const FileWithDetails* file = nullptr;
155157
mResult.getNextFile(file);
156158
while (file && mState == Running) {

0 commit comments

Comments
 (0)