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
2 changes: 1 addition & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
CheckUnusedFunctions checkUnusedFunctions(nullptr, nullptr, nullptr);

try {
Preprocessor preprocessor(mSettings, this);
Preprocessor preprocessor(mSettings, mSettings.nomsg, this);
std::set<std::string> configurations;

simplecpp::OutputList outputList;
Expand Down
19 changes: 10 additions & 9 deletions lib/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Directive::Directive(std::string _file, const int _linenr, const std::string &_s

char Preprocessor::macroChar = char(1);

Preprocessor::Preprocessor(Settings& settings, ErrorLogger *errorLogger) : mSettings(settings), mErrorLogger(errorLogger)
Preprocessor::Preprocessor(const Settings& settings, Suppressions &suppressions, ErrorLogger *errorLogger) : mSettings(settings), mSuppressions(suppressions), mErrorLogger(errorLogger)
{}

Preprocessor::~Preprocessor()
Expand Down Expand Up @@ -129,7 +129,7 @@ static bool parseInlineSuppressionCommentToken(const simplecpp::Token *tok, std:
return true;
}

static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &mSettings, std::list<BadInlineSuppression> &bad)
static void addinlineSuppressions(const simplecpp::TokenList &tokens, const Settings &settings, Suppressions &suppressions, std::list<BadInlineSuppression> &bad)
{
for (const simplecpp::Token *tok = tokens.cfront(); tok; tok = tok->next) {
if (!tok->comment)
Expand All @@ -155,8 +155,8 @@ static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &

// Relative filename
std::string relativeFilename(tok->location.file());
if (mSettings.relativePaths) {
for (const std::string & basePath : mSettings.basePaths) {
if (settings.relativePaths) {
for (const std::string & basePath : settings.basePaths) {
const std::string bp = basePath + "/";
if (relativeFilename.compare(0,bp.size(),bp)==0) {
relativeFilename = relativeFilename.substr(bp.size());
Expand All @@ -179,7 +179,7 @@ static void addinlineSuppressions(const simplecpp::TokenList &tokens, Settings &
suppr.fileName = relativeFilename;
suppr.lineNumber = tok->location.line;
suppr.thisAndNextLine = thisAndNextLine;
mSettings.nomsg.addSuppression(suppr);
suppressions.addSuppression(suppr);
}
}
}
Expand All @@ -189,10 +189,10 @@ void Preprocessor::inlineSuppressions(const simplecpp::TokenList &tokens)
if (!mSettings.inlineSuppressions)
return;
std::list<BadInlineSuppression> err;
::addinlineSuppressions(tokens, mSettings, err);
::addinlineSuppressions(tokens, mSettings, mSuppressions, err);
for (std::map<std::string,simplecpp::TokenList*>::const_iterator it = mTokenLists.cbegin(); it != mTokenLists.cend(); ++it) {
if (it->second)
::addinlineSuppressions(*it->second, mSettings, err);
::addinlineSuppressions(*it->second, mSettings, mSuppressions, err);
}
for (const BadInlineSuppression &bad : err) {
error(bad.location.file(), bad.location.line, bad.errmsg);
Expand Down Expand Up @@ -842,7 +842,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
errorMessage.errorId = errorId;
errorMessage.setFileName(std::move(fname));
errorMessage.lineNumber = linenr;
if (mSettings.nomsg.isSuppressed(errorMessage))
if (mSuppressions.isSuppressed(errorMessage))
return;

if (mErrorLogger) {
Expand All @@ -866,7 +866,8 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
{
Settings settings2(*settings);
Preprocessor preprocessor(settings2, errorLogger);
Suppressions supressions2;
Preprocessor preprocessor(settings2, supressions2, errorLogger);
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader);
preprocessor.error(emptyString, 1, "#error message"); // #error ..
Expand Down
6 changes: 4 additions & 2 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

class ErrorLogger;
class Settings;
class Suppressions;

/**
* @brief A preprocessor directive
Expand Down Expand Up @@ -83,7 +84,7 @@ class CPPCHECKLIB Preprocessor {
/** character that is inserted in expanded macros */
static char macroChar;

explicit Preprocessor(Settings& settings, ErrorLogger *errorLogger = nullptr);
explicit Preprocessor(const Settings& settings, Suppressions &suppressions, ErrorLogger *errorLogger = nullptr);
virtual ~Preprocessor();

void inlineSuppressions(const simplecpp::TokenList &tokens);
Expand Down Expand Up @@ -187,7 +188,8 @@ class CPPCHECKLIB 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);

Settings& mSettings;
const Settings& mSettings;
Suppressions &mSuppressions;
ErrorLogger *mErrorLogger;

/** list of all directives met while preprocessing file */
Expand Down
36 changes: 18 additions & 18 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class TestClass : public TestFixture {
Settings settings;
settings.severity.enable(Severity::warning);

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down Expand Up @@ -365,7 +365,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings0, nullptr);
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings0, this, &preprocessor);
Expand Down Expand Up @@ -519,7 +519,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings1, nullptr);
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings1, this, &preprocessor);
Expand Down Expand Up @@ -682,7 +682,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings0, nullptr);
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings0, this, &preprocessor);
Expand Down Expand Up @@ -1131,7 +1131,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings0, nullptr);
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings0, this, &preprocessor);
Expand Down Expand Up @@ -1607,7 +1607,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings1, nullptr);
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings1, this, &preprocessor);
Expand Down Expand Up @@ -2571,7 +2571,7 @@ class TestClass : public TestFixture {
settings0.certainty.setEnabled(Certainty::inconclusive, inconclusive);
settings0.severity.enable(Severity::warning);

Preprocessor preprocessor(settings0, nullptr);
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings0, this, &preprocessor);
Expand Down Expand Up @@ -2894,7 +2894,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down Expand Up @@ -3527,7 +3527,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings1, nullptr);
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings1, this, &preprocessor);
Expand Down Expand Up @@ -3567,7 +3567,7 @@ class TestClass : public TestFixture {
s = &settings0;
s->certainty.setEnabled(Certainty::inconclusive, inconclusive);

Preprocessor preprocessor(*s, nullptr);
Preprocessor preprocessor(*s, s->nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(s, this, &preprocessor);
Expand Down Expand Up @@ -7167,7 +7167,7 @@ class TestClass : public TestFixture {
// Check..
settings0.certainty.setEnabled(Certainty::inconclusive, true);

Preprocessor preprocessor(settings0, nullptr);
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings0, this, &preprocessor);
Expand Down Expand Up @@ -7205,7 +7205,7 @@ class TestClass : public TestFixture {
Settings settings;
settings.severity.enable(Severity::performance);

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down Expand Up @@ -7419,7 +7419,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings0, nullptr);
Preprocessor preprocessor(settings0, settings0.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings0, this, &preprocessor);
Expand Down Expand Up @@ -7537,7 +7537,7 @@ class TestClass : public TestFixture {
settings.severity.enable(Severity::warning);
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down Expand Up @@ -7886,7 +7886,7 @@ class TestClass : public TestFixture {
Settings settings;
settings.severity.enable(Severity::style);

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down Expand Up @@ -8064,7 +8064,7 @@ class TestClass : public TestFixture {
settings.safeChecks.classes = true;
settings.severity.enable(Severity::warning);

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand All @@ -8087,7 +8087,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings1, nullptr);
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings1, this, &preprocessor);
Expand Down Expand Up @@ -8286,7 +8286,7 @@ class TestClass : public TestFixture {
// Clear the error log
errout.str("");

Preprocessor preprocessor(settings1, nullptr);
Preprocessor preprocessor(settings1, settings1.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings1, this, &preprocessor);
Expand Down
2 changes: 1 addition & 1 deletion test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TestCondition : public TestFixture {
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());

Preprocessor preprocessor(*settings, nullptr);
Preprocessor preprocessor(*settings, settings->nomsg, nullptr);
preprocessor.setDirectives(tokens1);

// Tokenizer..
Expand Down
2 changes: 1 addition & 1 deletion test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class TestGarbage : public TestFixture {
std::string checkCodeInternal_(const std::string &code, const char* filename, const char* file, int line) {
errout.str("");

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down
8 changes: 4 additions & 4 deletions test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class TestOther : public TestFixture {
settings->certainty.setEnabled(Certainty::experimental, experimental);
settings->verbose = verbose;

Preprocessor preprocessor(*settings, nullptr);
Preprocessor preprocessor(*settings, settings->nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(settings, this, &preprocessor);
Expand Down Expand Up @@ -347,7 +347,7 @@ class TestOther : public TestFixture {
std::map<std::string, simplecpp::TokenList*> filedata;
simplecpp::preprocess(tokens2, tokens1, files, filedata, simplecpp::DUI());

Preprocessor preprocessor(*settings, nullptr);
Preprocessor preprocessor(*settings, settings->nomsg, nullptr);
preprocessor.setDirectives(tokens1);

// Tokenizer..
Expand Down Expand Up @@ -1548,7 +1548,7 @@ class TestOther : public TestFixture {
settings.severity.enable(Severity::style);
settings.standards.cpp = Standards::CPP03; // #5560

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizerCpp(&settings, this, &preprocessor);
Expand Down Expand Up @@ -1754,7 +1754,7 @@ class TestOther : public TestFixture {
settings.certainty.setEnabled(Certainty::inconclusive, inconclusive);
settings.platform.defaultSign = 's';

Preprocessor preprocessor(settings, nullptr);
Preprocessor preprocessor(settings, settings.nomsg, nullptr);

// Tokenize..
Tokenizer tokenizer(&settings, this, &preprocessor);
Expand Down
Loading