Skip to content

Commit

Permalink
Preprocessor: made mErrorLogger a reference (#6274)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 11, 2024
1 parent 25768b4 commit b9c535c
Show file tree
Hide file tree
Showing 24 changed files with 67 additions and 67 deletions.
4 changes: 2 additions & 2 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
return mExitCode;
}

Preprocessor preprocessor(mSettings, this);
Preprocessor preprocessor(mSettings, *this);

if (!preprocessor.loadFiles(tokens1, files))
return mExitCode;
Expand Down Expand Up @@ -1694,7 +1694,7 @@ void CppCheck::getErrorMessages(ErrorLogger &errorlogger)
(*it)->getErrorMessages(&errorlogger, &s);

CheckUnusedFunctions::getErrorMessages(errorlogger);
Preprocessor::getErrorMessages(&errorlogger, s);
Preprocessor::getErrorMessages(errorlogger, s);
}

void CppCheck::analyseClangTidy(const FileSettings &fileSettings)
Expand Down
20 changes: 10 additions & 10 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(const Settings& settings, ErrorLogger *errorLogger) : mSettings(settings), mErrorLogger(errorLogger)
Preprocessor::Preprocessor(const Settings& settings, ErrorLogger &errorLogger) : mSettings(settings), mErrorLogger(errorLogger)
{}

Preprocessor::~Preprocessor()
Expand Down Expand Up @@ -875,18 +875,18 @@ void Preprocessor::error(const std::string &filename, unsigned int linenr, const

locationList.emplace_back(file, linenr, 0);
}
mErrorLogger->reportErr(ErrorMessage(std::move(locationList),
mFile0,
Severity::error,
msg,
"preprocessorErrorDirective",
Certainty::normal));
mErrorLogger.reportErr(ErrorMessage(std::move(locationList),
mFile0,
Severity::error,
msg,
"preprocessorErrorDirective",
Certainty::normal));
}

// Report that include is missing
void Preprocessor::missingInclude(const std::string &filename, unsigned int linenr, const std::string &header, HeaderTypes headerType)
{
if (!mSettings.checks.isEnabled(Checks::missingInclude) || !mErrorLogger)
if (!mSettings.checks.isEnabled(Checks::missingInclude))
return;

std::list<ErrorMessage::FileLocation> locationList;
Expand All @@ -899,10 +899,10 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
"Include file: \"" + header + "\" not found.",
(headerType==SystemHeader) ? "missingIncludeSystem" : "missingInclude",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}

void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings &settings)
void Preprocessor::getErrorMessages(ErrorLogger &errorLogger, const Settings &settings)
{
Preprocessor preprocessor(settings, errorLogger);
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
Expand Down
6 changes: 3 additions & 3 deletions lib/preprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
/** character that is inserted in expanded macros */
static char macroChar;

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

void inlineSuppressions(const simplecpp::TokenList &tokens, SuppressionList &suppressions);
Expand Down Expand Up @@ -119,7 +119,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {

void simplifyPragmaAsm(simplecpp::TokenList *tokenList) const;

static void getErrorMessages(ErrorLogger *errorLogger, const Settings &settings);
static void getErrorMessages(ErrorLogger &errorLogger, const Settings &settings);

/**
* dump all directives present in source file
Expand All @@ -139,7 +139,7 @@ class CPPCHECKLIB WARN_UNUSED Preprocessor {
static bool hasErrors(const simplecpp::OutputList &outputList);

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

/** list of all directives met while preprocessing file */

Expand Down
8 changes: 4 additions & 4 deletions test/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ std::string PreprocessorHelper::getcode(Preprocessor &preprocessor, const std::s
return ret;
}

void PreprocessorHelper::preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer)
void PreprocessorHelper::preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger)
{
preprocess(code, files, tokenizer, simplecpp::DUI());
preprocess(code, files, tokenizer, errorlogger, simplecpp::DUI());
}

void PreprocessorHelper::preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, const simplecpp::DUI& dui)
void PreprocessorHelper::preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger, const simplecpp::DUI& dui)
{
std::istringstream istr(code);
const simplecpp::TokenList tokens1(istr, files, files[0]);
Expand All @@ -162,7 +162,7 @@ void PreprocessorHelper::preprocess(const char code[], std::vector<std::string>
// Tokenizer..
tokenizer.list.createTokens(std::move(tokens2));

const Preprocessor preprocessor(tokenizer.getSettings());
const Preprocessor preprocessor(tokenizer.getSettings(), errorlogger);
std::list<Directive> directives = preprocessor.createDirectives(tokens1);
tokenizer.setDirectives(std::move(directives));
}
4 changes: 2 additions & 2 deletions test/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class PreprocessorHelper
*/
static std::string getcode(Preprocessor &preprocessor, const std::string &filedata, const std::string &cfg, const std::string &filename, SuppressionList *inlineSuppression = nullptr);

static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer);
static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, const simplecpp::DUI& dui);
static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger);
static void preprocess(const char code[], std::vector<std::string> &files, Tokenizer& tokenizer, ErrorLogger& errorlogger, const simplecpp::DUI& dui);
};

namespace cppcheck {
Expand Down
2 changes: 1 addition & 1 deletion test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class TestBufferOverrun : public TestFixture {

std::vector<std::string> files(1, filename);
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
4 changes: 2 additions & 2 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8505,7 +8505,7 @@ class TestClass : public TestFixture {

std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

Expand Down Expand Up @@ -8912,7 +8912,7 @@ class TestClass : public TestFixture {

std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);

Expand Down
2 changes: 1 addition & 1 deletion test/testcondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class TestCondition : public TestFixture {
void check_(const char* file, int line, const char code[], const Settings &settings, const char* filename = "test.cpp") {
std::vector<std::string> files(1, filename);
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
2 changes: 1 addition & 1 deletion test/testincompletestatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestIncompleteStatement : public TestFixture {

std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings1, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenize..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
2 changes: 1 addition & 1 deletion test/testleakautovar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3072,7 +3072,7 @@ class TestLeakAutoVarRecursiveCountLimit : public TestFixture {
void checkP_(const char* file, int line, const char code[], bool cpp = false) {
std::vector<std::string> files(1, cpp?"test.cpp":"test.c");
Tokenizer tokenizer(settings, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
2 changes: 1 addition & 1 deletion test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class TestNullPointer : public TestFixture {

std::vector<std::string> files(1, "test.cpp");
Tokenizer tokenizer(settings1, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
2 changes: 1 addition & 1 deletion test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ class TestOther : public TestFixture {

std::vector<std::string> files(1, filename);
Tokenizer tokenizer(*settings, this);
PreprocessorHelper::preprocess(code, files, tokenizer);
PreprocessorHelper::preprocess(code, files, tokenizer, *this);

// Tokenizer..
ASSERT_LOC(tokenizer.simplifyTokens1(""), file, line);
Expand Down
Loading

0 comments on commit b9c535c

Please sign in to comment.