diff --git a/lib/preprocessor.h b/lib/preprocessor.h index f31265ff782..3d97050dc2e 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -99,15 +99,11 @@ class CPPCHECKLIB RemarkComment { * configurations that exist in a source file. */ class CPPCHECKLIB WARN_UNUSED Preprocessor { - // TODO: get rid of this - friend class TestPreprocessor; - public: /** character that is inserted in expanded macros */ static char macroChar; - explicit Preprocessor(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang); - virtual ~Preprocessor() = default; + Preprocessor(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang); void inlineSuppressions(SuppressionList &suppressions); @@ -146,11 +142,14 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { static bool hasErrors(const simplecpp::Output &output); +protected: + void reportOutput(const simplecpp::OutputList &outputList, bool showerror); + + static bool hasErrors(const simplecpp::OutputList &outputList); + private: void handleErrors(const simplecpp::OutputList &outputList, bool throwError); - void reportOutput(const simplecpp::OutputList &outputList, bool showerror); - static void simplifyPragmaAsmPrivate(simplecpp::TokenList &tokenList); /** @@ -164,8 +163,6 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor { 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); - static bool hasErrors(const simplecpp::OutputList &outputList); - void addRemarkComments(const simplecpp::TokenList &tokens, std::vector &remarkComments) const; simplecpp::TokenList& mTokens; diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index c4ac6f405ee..ada3a7e5c45 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -49,12 +49,21 @@ class TestPreprocessor : public TestFixture { TestPreprocessor() : TestFixture("TestPreprocessor") {} private: + class PreprocessorTest : public Preprocessor + { + friend class TestPreprocessor; + public: + PreprocessorTest(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang) + : Preprocessor(tokens, settings, errorLogger, lang) + {} + }; + template std::string expandMacros(const char (&code)[size], ErrorLogger &errorLogger) const { simplecpp::OutputList outputList; std::vector files; simplecpp::TokenList tokens1 = simplecpp::TokenList(code, files, "file.cpp", &outputList); - Preprocessor p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false)); + PreprocessorTest p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false)); simplecpp::TokenList tokens2 = p.preprocess("", files, true); p.reportOutput(outputList, true); return tokens2.stringify(); @@ -119,7 +128,7 @@ class TestPreprocessor : public TestFixture { simplecpp::TokenList tokens(code, size, files, Path::simplifyPath(filename), &outputList); // TODO: we should be using the actual Preprocessor implementation - Preprocessor preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false)); + PreprocessorTest preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false)); if (inlineSuppression) preprocessor.inlineSuppressions(*inlineSuppression); preprocessor.removeComments(); @@ -127,7 +136,7 @@ class TestPreprocessor : public TestFixture { preprocessor.reportOutput(outputList, true); - if (Preprocessor::hasErrors(outputList)) + if (PreprocessorTest::hasErrors(outputList)) return {}; std::map cfgcode;