Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

/**
Expand All @@ -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<RemarkComment> &remarkComments) const;

simplecpp::TokenList& mTokens;
Expand Down
15 changes: 12 additions & 3 deletions test/testpreprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t size>
std::string expandMacros(const char (&code)[size], ErrorLogger &errorLogger) const {
simplecpp::OutputList outputList;
std::vector<std::string> 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();
Expand Down Expand Up @@ -119,15 +128,15 @@ 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();
preprocessor.simplifyPragmaAsm();

preprocessor.reportOutput(outputList, true);

if (Preprocessor::hasErrors(outputList))
if (PreprocessorTest::hasErrors(outputList))
return {};

std::map<std::string, std::string> cfgcode;
Expand Down