Skip to content

Commit f85cc26

Browse files
committed
frontend
1 parent 8ddc13c commit f85cc26

17 files changed

Lines changed: 223 additions & 227 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ if(USE_BUNDLED_TINYXML2)
101101
endif()
102102
add_subdirectory(externals/simplecpp)
103103
add_subdirectory(lib) # CppCheck Library
104+
add_subdirectory(frontend)
104105
add_subdirectory(cli) # Client application
105106
add_subdirectory(test) # Tests
106107
add_subdirectory(gui) # Graphical application

Makefile

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@ ifndef INCLUDE_FOR_LIB
162162
INCLUDE_FOR_LIB=-Ilib -isystem externals -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2
163163
endif
164164

165+
ifndef INCLUDE_FOR_FE
166+
INCLUDE_FOR_FE=-Ilib
167+
endif
168+
165169
ifndef INCLUDE_FOR_CLI
166-
INCLUDE_FOR_CLI=-Ilib -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2
170+
INCLUDE_FOR_CLI=-Ilib -Ifrontend -isystem externals/picojson -isystem externals/simplecpp -isystem externals/tinyxml2
167171
endif
168172

169173
ifndef INCLUDE_FOR_TEST
@@ -252,6 +256,8 @@ LIBOBJ = $(libcppdir)/valueflow.o \
252256
EXTOBJ = externals/simplecpp/simplecpp.o \
253257
externals/tinyxml2/tinyxml2.o
254258

259+
FEOBJ = frontend/frontend.o
260+
255261
CLIOBJ = cli/cmdlineparser.o \
256262
cli/cppcheckexecutor.o \
257263
cli/executor.o \
@@ -344,12 +350,12 @@ TESTOBJ = test/fixture.o \
344350

345351
###### Targets
346352

347-
cppcheck: $(EXTOBJ) $(LIBOBJ) $(CLIOBJ)
353+
cppcheck: $(EXTOBJ) $(LIBOBJ) $(FEOBJ) $(CLIOBJ)
348354
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
349355

350356
all: cppcheck testrunner
351357

352-
testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) cli/cmdlineparser.o cli/cppcheckexecutor.o cli/executor.o cli/filelister.o cli/processexecutor.o cli/sehwrapper.o cli/signalhandler.o cli/singleexecutor.o cli/stacktrace.o cli/threadexecutor.o
358+
testrunner: $(EXTOBJ) $(TESTOBJ) $(LIBOBJ) $(FEOBJ) cli/cmdlineparser.o cli/cppcheckexecutor.o cli/executor.o cli/filelister.o cli/processexecutor.o cli/sehwrapper.o cli/signalhandler.o cli/singleexecutor.o cli/stacktrace.o cli/threadexecutor.o
353359
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS) $(LDFLAGS) $(RDYNAMIC)
354360

355361
test: all
@@ -653,6 +659,9 @@ $(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/addoninfo.h lib/as
653659
$(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
654660
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vfvalue.cpp
655661

662+
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
663+
$(CXX) ${INCLUDE_FOR_FE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ frontend/frontend.cpp
664+
656665
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
657666
$(CXX) ${INCLUDE_FOR_CLI} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ cli/cmdlineparser.cpp
658667

cli/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (BUILD_CLI)
66
list(REMOVE_ITEM srcs ${mainfile})
77

88
add_library(cli_objs OBJECT ${hdrs} ${srcs})
9-
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/)
9+
target_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib/ ${PROJECT_SOURCE_DIR}/frontend/)
1010
if(USE_BUNDLED_TINYXML2)
1111
target_externals_include_directories(cli_objs PRIVATE ${PROJECT_SOURCE_DIR}/externals/tinyxml2/)
1212
else()
@@ -26,7 +26,7 @@ if (BUILD_CLI)
2626
set_source_files_properties(processexecutor.cpp PROPERTIES COMPILE_FLAGS -Wno-reserved-identifier)
2727
endif()
2828

29-
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs>)
29+
list(APPEND cppcheck_SOURCES ${hdrs} ${mainfile} $<TARGET_OBJECTS:cli_objs> $<TARGET_OBJECTS:frontend_objs>)
3030
if (NOT BUILD_CORE_DLL)
3131
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:cppcheck-core>)
3232
list(APPEND cppcheck_SOURCES $<TARGET_OBJECTS:simplecpp_objs>)

cli/cli.vcxproj

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
</PropertyGroup>
8686
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
8787
<ClCompile>
88-
<AdditionalIncludeDirectories>..\lib;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
88+
<AdditionalIncludeDirectories>..\lib;..\frontend;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
8989
<BufferSecurityCheck>true</BufferSecurityCheck>
9090
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
9191
<Optimization>Disabled</Optimization>
@@ -114,7 +114,7 @@
114114
</ItemDefinitionGroup>
115115
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug-PCRE|x64'">
116116
<ClCompile>
117-
<AdditionalIncludeDirectories>..\lib;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
117+
<AdditionalIncludeDirectories>..\lib;..\frontend;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
118118
<BufferSecurityCheck>true</BufferSecurityCheck>
119119
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
120120
<Optimization>Disabled</Optimization>
@@ -143,7 +143,7 @@
143143
</ItemDefinitionGroup>
144144
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
145145
<ClCompile>
146-
<AdditionalIncludeDirectories>..\lib;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
146+
<AdditionalIncludeDirectories>..\lib;..\frontend;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
147147
<BufferSecurityCheck>false</BufferSecurityCheck>
148148
<Optimization>MaxSpeed</Optimization>
149149
<PreprocessorDefinitions>CPPCHECKLIB_IMPORT;TINYXML2_IMPORT;NDEBUG;WIN32;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -181,7 +181,7 @@
181181
</ItemDefinitionGroup>
182182
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release-PCRE|x64'">
183183
<ClCompile>
184-
<AdditionalIncludeDirectories>..\lib;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
184+
<AdditionalIncludeDirectories>..\lib;..\frontend;..\externals;..\externals\picojson;..\externals\simplecpp;..\externals\tinyxml2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
185185
<BufferSecurityCheck>false</BufferSecurityCheck>
186186
<Optimization>MaxSpeed</Optimization>
187187
<PreprocessorDefinitions>CPPCHECKLIB_IMPORT;TINYXML2_IMPORT;NDEBUG;WIN32;HAVE_RULES;_CRT_SECURE_NO_WARNINGS;WIN32_LEAN_AND_MEAN;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -231,6 +231,7 @@
231231
<ClInclude Include="singleexecutor.h" />
232232
<ClInclude Include="stacktrace.h" />
233233
<ClInclude Include="threadexecutor.h" />
234+
<ClInclude Include="..\frontend\frontend.h" />
234235
</ItemGroup>
235236
<ItemGroup>
236237
<ProjectReference Include="..\lib\cppcheck.vcxproj">
@@ -254,6 +255,7 @@
254255
<ClCompile Include="singleexecutor.cpp" />
255256
<ClCompile Include="stacktrace.cpp" />
256257
<ClCompile Include="threadexecutor.cpp" />
258+
<ClCompile Include="..\frontend\frontend.cpp" />
257259
</ItemGroup>
258260
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
259261
<ImportGroup Label="ExtensionTargets" />

cli/cli.vcxproj.filters

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
<ClInclude Include="cppcheckexecutor.h">
2424
<Filter>Header Files</Filter>
2525
</ClInclude>
26-
<ClInclude Include="cppcheckexecutorseh.h">
27-
<Filter>Header Files</Filter>
28-
</ClInclude>
2926
<ClInclude Include="signalhandler.h">
3027
<Filter>Header Files</Filter>
3128
</ClInclude>
@@ -44,6 +41,12 @@
4441
<ClInclude Include="singleexecutor.h">
4542
<Filter>Header Files</Filter>
4643
</ClInclude>
44+
<ClInclude Include="sehwrapper.h">
45+
<Filter>Header Files</Filter>
46+
</ClInclude>
47+
<ClInclude Include="..\frontend\frontend.h">
48+
<Filter>Header Files</Filter>
49+
</ClInclude>
4750
</ItemGroup>
4851
<ItemGroup Label="SourceFiles">
4952
<ClCompile Include="main.cpp">
@@ -55,9 +58,6 @@
5558
<ClCompile Include="cppcheckexecutor.cpp">
5659
<Filter>Source Files</Filter>
5760
</ClCompile>
58-
<ClCompile Include="cppcheckexecutorseh.cpp">
59-
<Filter>Source Files</Filter>
60-
</ClCompile>
6161
<ClCompile Include="signalhandler.cpp">
6262
<Filter>Source Files</Filter>
6363
</ClCompile>
@@ -79,6 +79,12 @@
7979
<ClCompile Include="singleexecutor.cpp">
8080
<Filter>Source Files</Filter>
8181
</ClCompile>
82+
<ClCompile Include="sehwrapper.cpp">
83+
<Filter>Source Files</Filter>
84+
</ClCompile>
85+
<ClCompile Include="..\frontend\frontend.cpp">
86+
<Filter>Source Files</Filter>
87+
</ClCompile>
8288
</ItemGroup>
8389
<ItemGroup>
8490
<ResourceCompile Include="version.rc">

cli/cmdlineparser.cpp

Lines changed: 3 additions & 34 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 (mEnforcedLang != 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(mEnforcedLang);
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) {

cli/cmdlineparser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class CmdLineParser {
176176
std::vector<std::string> mIgnoredPaths;
177177
Settings &mSettings;
178178
Suppressions &mSuppressions;
179+
/** @brief Name of the language that is enforced. Empty per default. */
179180
Standards::Language mEnforcedLang{Standards::Language::None};
180181
};
181182

frontend/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file(GLOB hdrs "*.h")
2+
file(GLOB srcs "*.cpp")
3+
4+
add_library(frontend_objs OBJECT ${hdrs} ${srcs})
5+
target_include_directories(frontend_objs PRIVATE ${PROJECT_SOURCE_DIR}/lib)

frontend/frontend.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2025 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "frontend.h"
20+
21+
#include "filesettings.h"
22+
#include "settings.h"
23+
24+
namespace frontend {
25+
void applyLang(std::list<FileSettings>& fileSettings, const Settings& settings, Standards::Language enforcedLang)
26+
{
27+
if (enforcedLang != Standards::Language::None)
28+
{
29+
// apply enforced language
30+
for (auto& fs : fileSettings)
31+
{
32+
if (settings.library.markupFile(fs.filename()))
33+
continue;
34+
fs.file.setLang(enforcedLang);
35+
}
36+
}
37+
else
38+
{
39+
// identify files
40+
for (auto& fs : fileSettings)
41+
{
42+
if (settings.library.markupFile(fs.filename()))
43+
continue;
44+
assert(fs.file.lang() == Standards::Language::None);
45+
bool header = false;
46+
fs.file.setLang(Path::identify(fs.filename(), settings.cppHeaderProbe, &header));
47+
// unknown extensions default to C++
48+
if (!header && fs.file.lang() == Standards::Language::None)
49+
fs.file.setLang(Standards::Language::CPP);
50+
}
51+
}
52+
53+
// enforce the language since markup files are special and do not adhere to the enforced language
54+
for (auto& fs : fileSettings)
55+
{
56+
if (settings.library.markupFile(fs.filename())) {
57+
assert(fs.file.lang() == Standards::Language::None);
58+
fs.file.setLang(Standards::Language::C);
59+
}
60+
}
61+
}
62+
}

frontend/frontend.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* -*- C++ -*-
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2025 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef FRONTEND_H
20+
#define FRONTEND_H
21+
22+
#include "standards.h"
23+
24+
#include <list>
25+
26+
struct FileSettings;
27+
class Settings;
28+
29+
namespace frontend
30+
{
31+
void applyLang(std::list<FileSettings> &fileSettings, const Settings &settings, Standards::Language enforcedLang);
32+
}
33+
34+
#endif // FRONTEND_H

0 commit comments

Comments
 (0)