From 1707820efdb77ca70a76a3142fc28b0efcae6823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 6 Apr 2024 23:32:38 +0200 Subject: [PATCH] Preprocessor: got rid of unused and test-only `preprocess()` overloads (#6249) --- lib/preprocessor.cpp | 36 ----------------------------------- lib/preprocessor.h | 44 +++---------------------------------------- test/testtokenize.cpp | 7 ++++--- 3 files changed, 7 insertions(+), 80 deletions(-) diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 938b52229cd..dd449ce3e92 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -32,7 +32,6 @@ #include #include #include -#include // back_inserter #include #include @@ -653,41 +652,6 @@ std::set Preprocessor::getConfigs(const simplecpp::TokenList &token return ret; } - -void Preprocessor::preprocess(std::istream &istr, std::map &result, const std::string &filename, const std::list &includePaths) -{ - (void)includePaths; - - simplecpp::OutputList outputList; - std::vector files; - const simplecpp::TokenList tokens1(istr, files, filename, &outputList); - - const std::set configs = getConfigs(tokens1); - - for (const std::string &c : configs) { - if (mSettings.userUndefs.find(c) == mSettings.userUndefs.end()) { - result[c] = getcode(tokens1, c, files, false); - } - } -} - -void Preprocessor::preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list &resultConfigurations, const std::string &filename, const std::list &includePaths) -{ - (void)includePaths; - - if (mFile0.empty()) - mFile0 = filename; - - simplecpp::OutputList outputList; - std::vector files; - const simplecpp::TokenList tokens1(srcCodeStream, files, filename, &outputList); - - const std::set configs = getConfigs(tokens1); - std::copy(configs.cbegin(), configs.cend(), std::back_inserter(resultConfigurations)); - - processedFile = tokens1.stringify(); -} - static void splitcfg(const std::string &cfg, std::list &defines, const std::string &defaultValue) { for (std::string::size_type defineStartPos = 0U; defineStartPos < cfg.size();) { diff --git a/lib/preprocessor.h b/lib/preprocessor.h index a902e1e953e..03b84af5d67 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -46,8 +46,7 @@ class SuppressionList; * */ -class CPPCHECKLIB Directive { -public: +struct CPPCHECKLIB Directive { /** name of (possibly included) file where directive is defined */ std::string file; @@ -110,38 +109,6 @@ class CPPCHECKLIB Preprocessor { void setPlatformInfo(simplecpp::TokenList *tokens) const; - /** - * Extract the code for each configuration - * @param istr The (file/string) stream to read from. - * @param result The map that will get the results - * @param filename The name of the file to check e.g. "src/main.cpp" - * @param includePaths List of paths where include files should be searched from, - * single path can be e.g. in format "include/". - * There must be a path separator at the end. Default parameter is empty list. - * Note that if path from given filename is also extracted and that is used as - * a last include path if include file was not found from earlier paths. - */ - void preprocess(std::istream &istr, std::map &result, const std::string &filename, const std::list &includePaths = std::list()); - - /** - * Extract the code for each configuration. Use this with getcode() to get the - * file data for each individual configuration. - * - * @param srcCodeStream The (file/string) stream to read from. - * @param processedFile Give reference to empty string as a parameter, - * function will fill processed file here. Use this also as a filedata parameter - * to getcode() if you received more than once configurations. - * @param resultConfigurations List of configurations. Pass these one by one - * to getcode() with processedFile. - * @param filename The name of the file to check e.g. "src/main.cpp" - * @param includePaths List of paths where include files should be searched from, - * single path can be e.g. in format "include/". - * There must be a path separator at the end. Default parameter is empty list. - * Note that if path from given filename is also extracted and that is used as - * a last include path if include file was not found from earlier paths. - */ - void preprocess(std::istream &srcCodeStream, std::string &processedFile, std::list &resultConfigurations, const std::string &filename, const std::list &includePaths); - simplecpp::TokenList preprocess(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files, bool throwError = false); std::string getcode(const simplecpp::TokenList &tokens1, const std::string &cfg, std::vector &files, const bool writeLocations); @@ -157,13 +124,6 @@ class CPPCHECKLIB Preprocessor { void simplifyPragmaAsm(simplecpp::TokenList *tokenList) const; -private: - - static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList); - -public: - - static void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings); /** @@ -176,6 +136,8 @@ class CPPCHECKLIB Preprocessor { static bool hasErrors(const simplecpp::Output &output); private: + static void simplifyPragmaAsmPrivate(simplecpp::TokenList *tokenList); + void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType); void error(const std::string &filename, unsigned int linenr, const std::string &msg); diff --git a/test/testtokenize.cpp b/test/testtokenize.cpp index 0076122a423..18f15edcb9d 100644 --- a/test/testtokenize.cpp +++ b/test/testtokenize.cpp @@ -6830,10 +6830,11 @@ class TestTokenizer : public TestFixture { // Preprocess file.. Preprocessor preprocessor(settings0); - std::list configurations; - std::string filedata; std::istringstream fin(raw_code); - preprocessor.preprocess(fin, filedata, configurations, emptyString, settings0.includePaths); + simplecpp::OutputList outputList; + std::vector files; + const simplecpp::TokenList tokens1(fin, files, emptyString, &outputList); + const std::string filedata = tokens1.stringify(); const std::string code = PreprocessorHelper::getcode(preprocessor, filedata, emptyString, emptyString); ASSERT_THROW(tokenizeAndStringify(code.c_str()), InternalError);