Skip to content

Commit 2fa74c5

Browse files
committed
added Regex::engine() / removed unnecessary Rule::engine
1 parent b5fbcca commit 2fa74c5

6 files changed

Lines changed: 13 additions & 6 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ $(libcppdir)/reverseanalyzer.o: lib/reverseanalyzer.cpp lib/addoninfo.h lib/anal
657657
$(libcppdir)/sarifreport.o: lib/sarifreport.cpp externals/picojson/picojson.h lib/addoninfo.h lib/check.h lib/checkers.h lib/config.h lib/cppcheck.h lib/errorlogger.h lib/errortypes.h lib/json.h lib/library.h lib/mathlib.h lib/platform.h lib/sarifreport.h lib/settings.h lib/standards.h lib/utils.h
658658
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/sarifreport.cpp
659659

660-
$(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errortypes.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/regex.h lib/rule.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/utils.h lib/vfvalue.h
660+
$(libcppdir)/settings.o: lib/settings.cpp externals/picojson/picojson.h lib/addoninfo.h lib/checkers.h lib/config.h lib/errortypes.h lib/json.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/rule.h lib/settings.h lib/standards.h lib/summaries.h lib/suppressions.h lib/utils.h lib/vfvalue.h
661661
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/settings.cpp
662662

663663
$(libcppdir)/standards.o: lib/standards.cpp externals/simplecpp/simplecpp.h lib/config.h lib/standards.h lib/utils.h

cli/cmdlineparser.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13421342
node = node->FirstChildElement("rule");
13431343
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
13441344
Rule rule;
1345+
Regex::Engine regexEngine = Regex::Engine::Unknown;
13451346

13461347
for (const tinyxml2::XMLElement *subnode = node->FirstChildElement(); subnode; subnode = subnode->NextSiblingElement()) {
13471348
const char * const subname = subnode->Name();
@@ -1374,7 +1375,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
13741375
else if (std::strcmp(subname, "engine") == 0) {
13751376
const char * const engine = empty_if_null(subtext);
13761377
if (std::strcmp(engine, "pcre") == 0) {
1377-
rule.engine = Regex::Engine::Pcre;
1378+
regexEngine = Regex::Engine::Pcre;
13781379
}
13791380
else {
13801381
mLogger.printError(std::string("unknown regex engine '") + engine + "'.");
@@ -1408,7 +1409,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
14081409
}
14091410

14101411
std::string regex_err;
1411-
auto regex = Regex::create(rule.pattern, rule.engine, regex_err);
1412+
auto regex = Regex::create(rule.pattern, regexEngine, regex_err);
14121413
if (!regex) {
14131414
mLogger.printError("unable to load rule-file '" + ruleFile + "' - pattern '" + rule.pattern + "' failed to compile (" + regex_err + ").");
14141415
return Result::Fail;

lib/regex.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ namespace {
179179
std::string compile();
180180
std::string match(const std::string& str, const MatchFn& matchFn) const override;
181181

182+
Engine engine() const override {
183+
return Engine::Pcre;
184+
}
185+
182186
private:
183187
std::string mPattern;
184188
pcre* mRe{};

lib/regex.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ class CPPCHECKLIB Regex
4444
Pcre = 1
4545
};
4646

47+
virtual Engine engine() const = 0;
48+
4749
static std::shared_ptr<Regex> create(std::string pattern, Engine engine, std::string& err);
4850
};
4951

lib/rule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
#ifdef HAVE_RULES
2323

2424
#include "errortypes.h"
25-
#include "regex.h"
2625

2726
#include <memory>
2827
#include <string>
2928

29+
class Regex;
30+
3031
/** Rule */
3132
struct Rule
3233
{
@@ -35,7 +36,6 @@ struct Rule
3536
std::string id = "rule"; // default id
3637
std::string summary;
3738
Severity severity = Severity::style; // default severity
38-
Regex::Engine engine = Regex::Engine::Pcre;
3939
std::shared_ptr<Regex> regex;
4040
};
4141
#endif // HAVE_RULES

oss-fuzz/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ $(libcppdir)/reverseanalyzer.o: ../lib/reverseanalyzer.cpp ../lib/addoninfo.h ..
327327
$(libcppdir)/sarifreport.o: ../lib/sarifreport.cpp ../externals/picojson/picojson.h ../lib/addoninfo.h ../lib/check.h ../lib/checkers.h ../lib/config.h ../lib/cppcheck.h ../lib/errorlogger.h ../lib/errortypes.h ../lib/json.h ../lib/library.h ../lib/mathlib.h ../lib/platform.h ../lib/sarifreport.h ../lib/settings.h ../lib/standards.h ../lib/utils.h
328328
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/sarifreport.cpp
329329

330-
$(libcppdir)/settings.o: ../lib/settings.cpp ../externals/picojson/picojson.h ../lib/addoninfo.h ../lib/checkers.h ../lib/config.h ../lib/errortypes.h ../lib/json.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/regex.h ../lib/rule.h ../lib/settings.h ../lib/standards.h ../lib/summaries.h ../lib/suppressions.h ../lib/utils.h ../lib/vfvalue.h
330+
$(libcppdir)/settings.o: ../lib/settings.cpp ../externals/picojson/picojson.h ../lib/addoninfo.h ../lib/checkers.h ../lib/config.h ../lib/errortypes.h ../lib/json.h ../lib/library.h ../lib/mathlib.h ../lib/path.h ../lib/platform.h ../lib/rule.h ../lib/settings.h ../lib/standards.h ../lib/summaries.h ../lib/suppressions.h ../lib/utils.h ../lib/vfvalue.h
331331
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/settings.cpp
332332

333333
$(libcppdir)/standards.o: ../lib/standards.cpp ../externals/simplecpp/simplecpp.h ../lib/config.h ../lib/standards.h ../lib/utils.h

0 commit comments

Comments
 (0)