Skip to content

Commit c4b988b

Browse files
authored
removed need for friend declaration of test class in Preprocessor / cleanups (#7918)
1 parent 9f50983 commit c4b988b

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

lib/preprocessor.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,11 @@ class CPPCHECKLIB RemarkComment {
9999
* configurations that exist in a source file.
100100
*/
101101
class CPPCHECKLIB WARN_UNUSED Preprocessor {
102-
// TODO: get rid of this
103-
friend class TestPreprocessor;
104-
105102
public:
106103
/** character that is inserted in expanded macros */
107104
static char macroChar;
108105

109-
explicit Preprocessor(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang);
110-
virtual ~Preprocessor() = default;
106+
Preprocessor(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang);
111107

112108
void inlineSuppressions(SuppressionList &suppressions);
113109

@@ -146,11 +142,14 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
146142

147143
static bool hasErrors(const simplecpp::Output &output);
148144

145+
protected:
146+
void reportOutput(const simplecpp::OutputList &outputList, bool showerror);
147+
148+
static bool hasErrors(const simplecpp::OutputList &outputList);
149+
149150
private:
150151
void handleErrors(const simplecpp::OutputList &outputList, bool throwError);
151152

152-
void reportOutput(const simplecpp::OutputList &outputList, bool showerror);
153-
154153
static void simplifyPragmaAsmPrivate(simplecpp::TokenList &tokenList);
155154

156155
/**
@@ -164,8 +163,6 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
164163
void missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType);
165164
void error(const std::string &filename, unsigned int linenr, const std::string &msg);
166165

167-
static bool hasErrors(const simplecpp::OutputList &outputList);
168-
169166
void addRemarkComments(const simplecpp::TokenList &tokens, std::vector<RemarkComment> &remarkComments) const;
170167

171168
simplecpp::TokenList& mTokens;

test/testpreprocessor.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,21 @@ class TestPreprocessor : public TestFixture {
4949
TestPreprocessor() : TestFixture("TestPreprocessor") {}
5050

5151
private:
52+
class PreprocessorTest : public Preprocessor
53+
{
54+
friend class TestPreprocessor;
55+
public:
56+
PreprocessorTest(simplecpp::TokenList& tokens, const Settings& settings, ErrorLogger &errorLogger, Standards::Language lang)
57+
: Preprocessor(tokens, settings, errorLogger, lang)
58+
{}
59+
};
60+
5261
template<size_t size>
5362
std::string expandMacros(const char (&code)[size], ErrorLogger &errorLogger) const {
5463
simplecpp::OutputList outputList;
5564
std::vector<std::string> files;
5665
simplecpp::TokenList tokens1 = simplecpp::TokenList(code, files, "file.cpp", &outputList);
57-
Preprocessor p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false));
66+
PreprocessorTest p(tokens1, settingsDefault, errorLogger, Path::identify(tokens1.getFiles()[0], false));
5867
simplecpp::TokenList tokens2 = p.preprocess("", files, true);
5968
p.reportOutput(outputList, true);
6069
return tokens2.stringify();
@@ -119,15 +128,15 @@ class TestPreprocessor : public TestFixture {
119128

120129
simplecpp::TokenList tokens(code, size, files, Path::simplifyPath(filename), &outputList);
121130
// TODO: we should be using the actual Preprocessor implementation
122-
Preprocessor preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
131+
PreprocessorTest preprocessor(tokens, settings, errorlogger, Path::identify(tokens.getFiles()[0], false));
123132
if (inlineSuppression)
124133
preprocessor.inlineSuppressions(*inlineSuppression);
125134
preprocessor.removeComments();
126135
preprocessor.simplifyPragmaAsm();
127136

128137
preprocessor.reportOutput(outputList, true);
129138

130-
if (Preprocessor::hasErrors(outputList))
139+
if (PreprocessorTest::hasErrors(outputList))
131140
return {};
132141

133142
std::map<std::string, std::string> cfgcode;

0 commit comments

Comments
 (0)