From adc5e46ee2f4a4ee1153565dba31c56fbc59b74a Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 10 Apr 2024 14:59:44 +0200 Subject: [PATCH] testrunner: small `PreprocessorHelper` cleanup --- test/helpers.cpp | 20 +++----------------- test/helpers.h | 3 +-- test/testcondition.cpp | 4 +--- test/testother.cpp | 4 +--- test/testtokenize.cpp | 3 +-- test/testtype.cpp | 4 +--- test/testunusedvar.cpp | 6 ++---- 7 files changed, 10 insertions(+), 34 deletions(-) diff --git a/test/helpers.cpp b/test/helpers.cpp index e0b5fdbdf6d..a639d27ec42 100644 --- a/test/helpers.cpp +++ b/test/helpers.cpp @@ -146,25 +146,10 @@ std::string PreprocessorHelper::getcode(Preprocessor &preprocessor, const std::s void PreprocessorHelper::preprocess(const char code[], std::vector &files, Tokenizer& tokenizer) { - // Raw Tokens.. - std::istringstream istr(code); - const simplecpp::TokenList tokens1(istr, files, files[0]); - - // Preprocess.. - simplecpp::TokenList tokens2(files); - std::map filedata; - simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI()); - - // Tokenizer.. - tokenizer.list.createTokens(std::move(tokens2)); -} - -void PreprocessorHelper::preprocess(Preprocessor &preprocessor, const char code[], std::vector &files, Tokenizer& tokenizer) -{ - preprocess(preprocessor, code, files, tokenizer, simplecpp::DUI()); + preprocess(code, files, tokenizer, simplecpp::DUI()); } -void PreprocessorHelper::preprocess(Preprocessor &preprocessor, const char code[], std::vector &files, Tokenizer& tokenizer, const simplecpp::DUI& dui) +void PreprocessorHelper::preprocess(const char code[], std::vector &files, Tokenizer& tokenizer, const simplecpp::DUI& dui) { std::istringstream istr(code); const simplecpp::TokenList tokens1(istr, files, files[0]); @@ -177,6 +162,7 @@ void PreprocessorHelper::preprocess(Preprocessor &preprocessor, const char code[ // Tokenizer.. tokenizer.list.createTokens(std::move(tokens2)); + const Preprocessor preprocessor(tokenizer.getSettings()); std::list directives = preprocessor.createDirectives(tokens1); tokenizer.setDirectives(std::move(directives)); } diff --git a/test/helpers.h b/test/helpers.h index 130748f4fc0..fbc8b755ec1 100644 --- a/test/helpers.h +++ b/test/helpers.h @@ -151,8 +151,7 @@ class PreprocessorHelper static std::string getcode(Preprocessor &preprocessor, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr); static void preprocess(const char code[], std::vector &files, Tokenizer& tokenizer); - static void preprocess(Preprocessor &preprocessor, const char code[], std::vector &files, Tokenizer& tokenizer); - static void preprocess(Preprocessor &preprocessor, const char code[], std::vector &files, Tokenizer& tokenizer, const simplecpp::DUI& dui); + static void preprocess(const char code[], std::vector &files, Tokenizer& tokenizer, const simplecpp::DUI& dui); }; namespace cppcheck { diff --git a/test/testcondition.cpp b/test/testcondition.cpp index d1b42b18cc6..05266e8db93 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -21,7 +21,6 @@ #include "fixture.h" #include "helpers.h" #include "platform.h" -#include "preprocessor.h" #include "settings.h" #include "tokenize.h" @@ -127,10 +126,9 @@ class TestCondition : public TestFixture { #define check(...) check_(__FILE__, __LINE__, __VA_ARGS__) void check_(const char* file, int line, const char code[], const Settings &settings, const char* filename = "test.cpp") { - Preprocessor preprocessor(settings); std::vector files(1, filename); Tokenizer tokenizer(settings, this); - PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer); + PreprocessorHelper::preprocess(code, files, tokenizer); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); diff --git a/test/testother.cpp b/test/testother.cpp index 6171845505e..2caae6262d3 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -21,7 +21,6 @@ #include "fixture.h" #include "helpers.h" #include "platform.h" -#include "preprocessor.h" #include "settings.h" #include "standards.h" #include "tokenize.h" @@ -331,10 +330,9 @@ class TestOther : public TestFixture { settings->standards.cpp = Standards::CPPLatest; settings->certainty.enable(Certainty::inconclusive); - Preprocessor preprocessor(*settings); std::vector files(1, filename); Tokenizer tokenizer(*settings, this); - PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer); + PreprocessorHelper::preprocess(code, files, tokenizer); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index eab7901084b..a79e168e049 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -7674,10 +7674,9 @@ class TestTokenizer : public TestFixture { std::string checkHdrs_(const char* file, int line, const char code[], bool checkHeadersFlag) { const Settings settings = settingsBuilder().checkHeaders(checkHeadersFlag).build(); - Preprocessor preprocessor(settings0); std::vector files(1, "test.cpp"); Tokenizer tokenizer(settings, this); - PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer); + PreprocessorHelper::preprocess(code, files, tokenizer); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); diff --git a/test/testtype.cpp b/test/testtype.cpp index d96ad4661fc..34ba2f55268 100644 --- a/test/testtype.cpp +++ b/test/testtype.cpp @@ -21,7 +21,6 @@ #include "fixture.h" #include "helpers.h" #include "platform.h" -#include "preprocessor.h" #include "settings.h" #include "standards.h" #include "tokenize.h" @@ -65,10 +64,9 @@ class TestType : public TestFixture { void checkP_(const char* file, int line, const char code[], const Settings& settings, const char filename[] = "test.cpp", const simplecpp::DUI& dui = simplecpp::DUI()) { const Settings settings1 = settingsBuilder(settings).severity(Severity::warning).severity(Severity::portability).build(); - Preprocessor preprocessor(settings1); std::vector files(1, filename); Tokenizer tokenizer(settings1, this); - PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer, dui); + PreprocessorHelper::preprocess(code, files, tokenizer, dui); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 8ae6de2019b..d390ed628a3 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -276,9 +276,8 @@ class TestUnusedVar : public TestFixture { #define checkStructMemberUsageP(...) checkStructMemberUsageP_(__FILE__, __LINE__, __VA_ARGS__) void checkStructMemberUsageP_(const char* file, int line, const char code[]) { std::vector files(1, "test.cpp"); - Preprocessor preprocessor(settings); Tokenizer tokenizer(settings, this); - PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer); + PreprocessorHelper::preprocess(code, files, tokenizer); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line); @@ -290,10 +289,9 @@ class TestUnusedVar : public TestFixture { #define checkFunctionVariableUsageP(...) checkFunctionVariableUsageP_(__FILE__, __LINE__, __VA_ARGS__) void checkFunctionVariableUsageP_(const char* file, int line, const char code[], const char* filename = "test.cpp") { - Preprocessor preprocessor(settings); std::vector files(1, filename); Tokenizer tokenizer(settings, this); - PreprocessorHelper::preprocess(preprocessor, code, files, tokenizer); + PreprocessorHelper::preprocess(code, files, tokenizer); // Tokenizer.. ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);