Skip to content

Commit 3751f49

Browse files
committed
extracted Rule from settings.h to rule.h
1 parent 8c14fc7 commit 3751f49

11 files changed

Lines changed: 263 additions & 211 deletions

File tree

Makefile

Lines changed: 135 additions & 135 deletions
Large diffs are not rendered by default.

cli/cmdlineparser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757

5858
#ifdef HAVE_RULES
5959
#include "regex.h"
60+
#include "rule.h"
6061

6162
// xml is used for rules
6263
#include "xml.h"
@@ -1304,7 +1305,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13041305
// Rule given at command line
13051306
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
13061307
#ifdef HAVE_RULES
1307-
Settings::Rule rule;
1308+
Rule rule;
13081309
rule.pattern = 7 + argv[i];
13091310

13101311
if (rule.pattern.empty()) {
@@ -1340,7 +1341,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13401341
if (node && strcmp(node->Value(), "rules") == 0)
13411342
node = node->FirstChildElement("rule");
13421343
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
1343-
Settings::Rule rule;
1344+
Rule rule;
13441345

13451346
for (const tinyxml2::XMLElement *subnode = node->FirstChildElement(); subnode; subnode = subnode->NextSiblingElement()) {
13461347
const char * const subname = subnode->Name();

gui/test/projectfile/testprojectfile.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "settings.h"
2525
#include "suppressions.h"
2626

27+
#ifdef HAVE_RULES
28+
#include "rule.h"
29+
#endif
30+
2731
#include <QFile>
2832
#include <QIODevice>
2933
#include <QList>
@@ -38,6 +42,7 @@ const char Settings::SafeChecks::XmlExternalFunctions[] = "external-functions";
3842
const char Settings::SafeChecks::XmlInternalFunctions[] = "internal-functions";
3943
const char Settings::SafeChecks::XmlExternalVariables[] = "external-variables";
4044
Settings::Settings() : maxCtuDepth(10) {}
45+
Settings::~Settings() = default;
4146
Platform::Platform() = default;
4247
Library::Library() = default;
4348
Library::~Library() = default;

lib/cppcheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747

4848
#ifdef HAVE_RULES
4949
#include "regex.h"
50+
#include "rule.h"
5051
#endif
5152

5253
#include <algorithm>
@@ -1415,7 +1416,7 @@ void CppCheck::checkNormalTokens(const Tokenizer &tokenizer, AnalyzerInformation
14151416
#ifdef HAVE_RULES
14161417
bool CppCheck::hasRule(const std::string &tokenlist) const
14171418
{
1418-
return std::any_of(mSettings.rules.cbegin(), mSettings.rules.cend(), [&](const Settings::Rule& rule) {
1419+
return std::any_of(mSettings.rules.cbegin(), mSettings.rules.cend(), [&](const Rule& rule) {
14191420
return rule.tokenlist == tokenlist;
14201421
});
14211422
}
@@ -1433,7 +1434,7 @@ void CppCheck::executeRules(const std::string &tokenlist, const TokenList &list)
14331434
str += tok->str();
14341435
}
14351436

1436-
for (const Settings::Rule &rule : mSettings.rules) {
1437+
for (const Rule &rule : mSettings.rules) {
14371438
if (rule.tokenlist != tokenlist)
14381439
continue;
14391440

lib/cppcheck.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
<ClInclude Include="programmemory.h" />
169169
<ClInclude Include="regex.h" />
170170
<ClInclude Include="reverseanalyzer.h" />
171+
<ClInclude Include="rule.h" />
171172
<ClInclude Include="sarifreport.h" />
172173
<ClInclude Include="settings.h" />
173174
<ClInclude Include="smallvector.h" />

lib/rule.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* -*- C++ -*-
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2026 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 ruleH
20+
#define ruleH
21+
22+
#ifdef HAVE_RULES
23+
24+
#include "errortypes.h"
25+
#include "regex.h"
26+
27+
#include <memory>
28+
#include <string>
29+
30+
/** Rule */
31+
struct Rule
32+
{
33+
std::string tokenlist = "normal"; // use normal tokenlist
34+
std::string pattern;
35+
std::string id = "rule"; // default id
36+
std::string summary;
37+
Severity severity = Severity::style; // default severity
38+
Regex::Engine engine = Regex::Engine::Pcre;
39+
std::shared_ptr<Regex> regex;
40+
};
41+
#endif // HAVE_RULES
42+
43+
#endif // ruleH

lib/settings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include "suppressions.h"
2525
#include "vfvalue.h"
2626

27+
#ifdef HAVE_RULES
28+
#include "rule.h"
29+
#endif
30+
2731
#include <cctype>
2832
#include <cstdlib>
2933
#include <cstring>
@@ -69,6 +73,11 @@ Settings::Settings()
6973
pid = getPid();
7074
}
7175

76+
Settings::~Settings() = default;
77+
78+
Settings::Settings(const Settings&) = default;
79+
Settings & Settings::operator=(const Settings &) = default;
80+
7281
std::string Settings::loadCppcheckCfg(Settings& settings, Suppressions& suppressions, bool debug)
7382
{
7483
static const std::string cfgFilename = "cppcheck.cfg";

lib/settings.h

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,13 @@
4444
#endif
4545

4646
#ifdef HAVE_RULES
47-
#include "errortypes.h"
48-
#include "regex.h"
49-
50-
#include <memory>
51-
52-
class Regex;
53-
#else
54-
enum class Severity : std::uint8_t;
47+
struct Rule;
5548
#endif
56-
5749
struct Suppressions;
5850
namespace ValueFlow {
5951
class Value;
6052
}
53+
enum class Severity : std::uint8_t;
6154
enum class Certainty : std::uint8_t;
6255
enum class Checks : std::uint8_t;
6356

@@ -115,6 +108,10 @@ class CPPCHECKLIB WARN_UNUSED Settings {
115108

116109
public:
117110
Settings();
111+
~Settings();
112+
113+
Settings(const Settings&);
114+
Settings& operator=(const Settings&);
118115

119116
static std::string loadCppcheckCfg(Settings& settings, Suppressions& suppressions, bool debug = false);
120117

@@ -372,17 +369,6 @@ class CPPCHECKLIB WARN_UNUSED Settings {
372369
int reportProgress{-1};
373370

374371
#ifdef HAVE_RULES
375-
/** Rule */
376-
struct CPPCHECKLIB Rule {
377-
std::string tokenlist = "normal"; // use normal tokenlist
378-
std::string pattern;
379-
std::string id = "rule"; // default id
380-
std::string summary;
381-
Severity severity = Severity::style; // default severity
382-
Regex::Engine engine = Regex::Engine::Pcre;
383-
std::shared_ptr<Regex> regex;
384-
};
385-
386372
/**
387373
* @brief Extra rules
388374
*/

0 commit comments

Comments
 (0)