Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made more mErrorLogger members references #6276

Merged
merged 2 commits into from
Apr 11, 2024
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
6 changes: 3 additions & 3 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ unsigned int CppCheck::checkClang(const std::string &path)
}

try {
Tokenizer tokenizer(mSettings, this);
Tokenizer tokenizer(mSettings, *this);
tokenizer.list.appendFileIfNew(path);
std::istringstream ast(output2);
clangimport::parseClangAstDump(tokenizer, ast);
Expand Down Expand Up @@ -657,7 +657,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
if (mSettings.library.markupFile(filename)) {
if (mUnusedFunctionsCheck && mSettings.useSingleJob() && mSettings.buildDir.empty()) {
// this is not a real source file - we just want to tokenize it. treat it as C anyways as the language needs to be determined.
Tokenizer tokenizer(mSettings, this);
Tokenizer tokenizer(mSettings, *this);
tokenizer.list.setLang(Standards::Language::C);
if (fileStream) {
tokenizer.list.createTokens(*fileStream, filename);
Expand Down Expand Up @@ -886,7 +886,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
continue;
}

Tokenizer tokenizer(mSettings, this);
Tokenizer tokenizer(mSettings, *this);
if (mSettings.showtime != SHOWTIME_MODES::SHOWTIME_NONE)
tokenizer.setTimerResults(&s_timerResults);
tokenizer.setDirectives(directives); // TODO: how to avoid repeated copies?
Expand Down
25 changes: 12 additions & 13 deletions lib/symboldatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#include <unordered_set>
//---------------------------------------------------------------------------

SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger* errorLogger)
SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger& errorLogger)
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger)
{
if (!mTokenizer.tokens())
Expand Down Expand Up @@ -169,10 +169,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
// find all scopes
for (const Token *tok = mTokenizer.tokens(); tok; tok = tok ? tok->next() : nullptr) {
// #5593 suggested to add here:
if (mErrorLogger)
mErrorLogger->reportProgress(mTokenizer.list.getSourceFilePath(),
"SymbolDatabase",
tok->progressValue());
mErrorLogger.reportProgress(mTokenizer.list.getSourceFilePath(),
"SymbolDatabase",
tok->progressValue());
// Locate next class
if ((tok->isCpp() && tok->isKeyword() &&
((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
Expand Down Expand Up @@ -2087,14 +2086,14 @@ void SymbolDatabase::validateExecutableScopes() const
for (std::size_t i = 0; i < functions; ++i) {
const Scope* const scope = functionScopes[i];
const Function* const function = scope->function;
if (mErrorLogger && scope->isExecutable() && !function) {
if (scope->isExecutable() && !function) {
const std::list<const Token*> callstack(1, scope->classDef);
const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function.";
const ErrorMessage errmsg(callstack, &mTokenizer.list, Severity::debug,
"symbolDatabaseWarning",
msg,
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
}
}
Expand Down Expand Up @@ -2152,7 +2151,7 @@ void SymbolDatabase::debugSymbolDatabase() const
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug())
continue;
if (mErrorLogger && tok->getTokenDebug() == TokenDebug::ValueType) {
if (tok->getTokenDebug() == TokenDebug::ValueType) {

std::string msg = "Value type is ";
ErrorPath errorPath;
Expand All @@ -2164,7 +2163,7 @@ void SymbolDatabase::debugSymbolDatabase() const
msg += "missing";
}
errorPath.emplace_back(tok, "");
mErrorLogger->reportErr(
mErrorLogger.reportErr(
{errorPath, &mTokenizer.list, Severity::debug, "valueType", msg, CWE{0}, Certainty::normal});
}
}
Expand Down Expand Up @@ -3584,27 +3583,27 @@ std::string Type::name() const

void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, const std::string &msg) const
{
if (tok && mSettings.debugwarnings && mErrorLogger) {
if (tok && mSettings.debugwarnings) {
const std::list<const Token*> locationList(1, tok);
const ErrorMessage errmsg(locationList, &mTokenizer.list,
Severity::debug,
type,
msg,
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
}

void SymbolDatabase::returnImplicitIntError(const Token *tok) const
{
if (tok && mSettings.severity.isEnabled(Severity::portability) && (tok->isC() && mSettings.standards.c != Standards::C89) && mErrorLogger) {
if (tok && mSettings.severity.isEnabled(Severity::portability) && (tok->isC() && mSettings.standards.c != Standards::C89)) {
const std::list<const Token*> locationList(1, tok);
const ErrorMessage errmsg(locationList, &mTokenizer.list,
Severity::portability,
"returnImplicitInt",
"Omitted return type of function '" + tok->str() + "' defaults to int, this is not supported by ISO C99 and later standards.",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/symboldatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ class CPPCHECKLIB ValueType {
class CPPCHECKLIB SymbolDatabase {
friend class TestSymbolDatabase;
public:
SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger* errorLogger);
SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger& errorLogger);
~SymbolDatabase();

/** @brief Information about all namespaces/classes/structures */
Expand Down Expand Up @@ -1467,7 +1467,7 @@ class CPPCHECKLIB SymbolDatabase {

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

/** variable symbol table */
std::vector<const Variable *> mVariableList;
Expand Down
36 changes: 18 additions & 18 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1170,14 +1170,14 @@ void TemplateSimplifier::useDefaultArgumentValues(TokenAndName &declaration)
while (it != eq.cend()) {
// check for end
if (!it->end) {
if (mSettings.debugwarnings && mErrorLogger && mSettings.severity.isEnabled(Severity::debug)) {
if (mSettings.debugwarnings && mSettings.severity.isEnabled(Severity::debug)) {
const std::list<const Token*> locationList(1, it->eq);
const ErrorMessage errmsg(locationList, &mTokenizer.list,
Severity::debug,
"noparamend",
"TemplateSimplifier couldn't find end of template parameter.",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
break;
}
Expand Down Expand Up @@ -3078,7 +3078,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
numberOfTemplateInstantiations = mTemplateInstantiations.size();
++recursiveCount;
if (recursiveCount > mSettings.maxTemplateRecursion) {
if (mErrorLogger && mSettings.severity.isEnabled(Severity::information)) {
if (mSettings.severity.isEnabled(Severity::information)) {
std::list<std::string> typeStringsUsedInTemplateInstantiation;
const std::string typeForNewName = templateDeclaration.name() + "<" + getNewName(instantiation.token(), typeStringsUsedInTemplateInstantiation) + ">";

Expand All @@ -3091,7 +3091,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
+ std::to_string(mSettings.maxTemplateRecursion)
+ ") reached for template '"+typeForNewName+"'. You might want to limit Cppcheck recursion.",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}

// bail out..
Expand Down Expand Up @@ -3159,8 +3159,8 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
continue;

Token * const tok2 = instantiation.token();
if (mErrorLogger && !mTokenList.getFiles().empty())
mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());
if (!mTokenList.getFiles().empty())
mErrorLogger.reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());

if (maxtime > 0 && std::time(nullptr) > maxtime) {
if (mSettings.debugwarnings) {
Expand All @@ -3171,7 +3171,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
"Template instantiation maximum time exceeded",
"templateMaxTime",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
return false;
}
Expand Down Expand Up @@ -3201,10 +3201,10 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(

if ((typeForNewName.empty() && !templateDeclaration.isVariadic()) ||
(!typeParametersInDeclaration.empty() && !instantiateMatch(tok2, typeParametersInDeclaration.size(), templateDeclaration.isVariadic(), nullptr))) {
if (printDebug && mErrorLogger) {
if (printDebug) {
std::list<const Token *> callstack(1, tok2);
mErrorLogger->reportErr(ErrorMessage(callstack, &mTokenList, Severity::debug, "templateInstantiation",
"Failed to instantiate template \"" + instantiation.name() + "\". The checking continues anyway.", Certainty::normal));
mErrorLogger.reportErr(ErrorMessage(callstack, &mTokenList, Severity::debug, "templateInstantiation",
"Failed to instantiate template \"" + instantiation.name() + "\". The checking continues anyway.", Certainty::normal));
}
if (typeForNewName.empty())
continue;
Expand All @@ -3229,8 +3229,8 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
// TODO: remove the specialized check and handle all uninstantiated templates someday.
if (!instantiated && specialized) {
auto * tok2 = const_cast<Token *>(templateDeclaration.nameToken());
if (mErrorLogger && !mTokenList.getFiles().empty())
mErrorLogger->reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());
if (!mTokenList.getFiles().empty())
mErrorLogger.reportProgress(mTokenList.getFiles()[0], "TemplateSimplifier::simplifyTemplateInstantiations()", tok2->progressValue());

if (maxtime > 0 && std::time(nullptr) > maxtime) {
if (mSettings.debugwarnings) {
Expand All @@ -3241,7 +3241,7 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
"Template instantiation maximum time exceeded",
"templateMaxTime",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
return false;
}
Expand Down Expand Up @@ -3278,10 +3278,10 @@ bool TemplateSimplifier::simplifyTemplateInstantiations(
std::string typeForNewName = getNewName(tok2, typeStringsUsedInTemplateInstantiation);

if (typeForNewName.empty()) {
if (printDebug && mErrorLogger) {
if (printDebug) {
std::list<const Token *> callstack(1, tok2);
mErrorLogger->reportErr(ErrorMessage(callstack, &mTokenList, Severity::debug, "templateInstantiation",
"Failed to instantiate template \"" + templateDeclaration.name() + "\". The checking continues anyway.", Certainty::normal));
mErrorLogger.reportErr(ErrorMessage(callstack, &mTokenList, Severity::debug, "templateInstantiation",
"Failed to instantiate template \"" + templateDeclaration.name() + "\". The checking continues anyway.", Certainty::normal));
}
return false;
}
Expand Down Expand Up @@ -3972,14 +3972,14 @@ void TemplateSimplifier::simplifyTemplates(const std::time_t maxtime)
}

if (passCount == passCountMax) {
if (mSettings.debugwarnings && mErrorLogger) {
if (mSettings.debugwarnings) {
const std::list<const Token*> locationList(1, mTokenList.front());
const ErrorMessage errmsg(locationList, &mTokenizer.list,
Severity::debug,
"debug",
"TemplateSimplifier: pass count limit hit before simplifications were finished.",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/templatesimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ class CPPCHECKLIB TemplateSimplifier {
Tokenizer &mTokenizer;
TokenList &mTokenList;
const Settings &mSettings;
ErrorLogger *mErrorLogger;
ErrorLogger &mErrorLogger;
bool mChanged{};

std::list<TokenAndName> mTemplateDeclarations;
Expand Down
30 changes: 13 additions & 17 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ static bool isClassStructUnionEnumStart(const Token * tok)

//---------------------------------------------------------------------------

Tokenizer::Tokenizer(const Settings &settings, ErrorLogger *errorLogger) :
Tokenizer::Tokenizer(const Settings &settings, ErrorLogger &errorLogger) :
list(&settings),
mSettings(settings),
mErrorLogger(errorLogger),
Expand Down Expand Up @@ -1141,22 +1141,22 @@ void Tokenizer::simplifyTypedefCpp()
const std::time_t maxTime = mSettings.typedefMaxTime > 0 ? std::time(nullptr) + mSettings.typedefMaxTime: 0;

for (Token *tok = list.front(); tok; tok = tok->next()) {
if (mErrorLogger && !list.getFiles().empty())
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());
if (!list.getFiles().empty())
mErrorLogger.reportProgress(list.getFiles()[0], "Tokenize (typedef)", tok->progressValue());

if (Settings::terminated())
return;

if (maxTime > 0 && std::time(nullptr) > maxTime) {
if (mErrorLogger && mSettings.debugwarnings) {
if (mSettings.debugwarnings) {
ErrorMessage::FileLocation loc(list.getFiles()[0], 0, 0);
ErrorMessage errmsg({std::move(loc)},
emptyString,
Severity::debug,
"Typedef simplification instantiation maximum time exceeded",
"typedefMaxTime",
Certainty::normal);
mErrorLogger->reportErr(errmsg);
mErrorLogger.reportErr(errmsg);
}
return;
}
Expand Down Expand Up @@ -2876,8 +2876,8 @@ bool Tokenizer::simplifyUsing()
std::list<Using> usingList;

for (Token *tok = list.front(); tok; tok = tok->next()) {
if (mErrorLogger && !list.getFiles().empty())
mErrorLogger->reportProgress(list.getFiles()[0], "Tokenize (using)", tok->progressValue());
if (!list.getFiles().empty())
mErrorLogger.reportProgress(list.getFiles()[0], "Tokenize (using)", tok->progressValue());

if (Settings::terminated())
return substitute;
Expand Down Expand Up @@ -3342,7 +3342,7 @@ bool Tokenizer::simplifyUsing()

void Tokenizer::simplifyUsingError(const Token* usingStart, const Token* usingEnd)
{
if (mSettings.debugwarnings && mErrorLogger) {
if (mSettings.debugwarnings) {
std::string str;
for (const Token *tok = usingStart; tok && tok != usingEnd; tok = tok->next()) {
if (!str.empty())
Expand All @@ -3351,8 +3351,8 @@ void Tokenizer::simplifyUsingError(const Token* usingStart, const Token* usingEn
}
str += " ;";
std::list<const Token *> callstack(1, usingStart);
mErrorLogger->reportErr(ErrorMessage(callstack, &list, Severity::debug, "simplifyUsing",
"Failed to parse \'" + str + "\'. The checking continues anyway.", Certainty::normal));
mErrorLogger.reportErr(ErrorMessage(callstack, &list, Severity::debug, "simplifyUsing",
"Failed to parse \'" + str + "\'. The checking continues anyway.", Certainty::normal));
}
}

Expand Down Expand Up @@ -3405,12 +3405,11 @@ bool Tokenizer::simplifyTokens1(const std::string &configuration)
const bool doValueFlow = !disableValueflowEnv || (std::strcmp(disableValueflowEnv, "1") != 0);

if (doValueFlow) {
assert(mErrorLogger);
if (mTimerResults) {
Timer t("Tokenizer::simplifyTokens1::ValueFlow", mSettings.showtime, mTimerResults);
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
ValueFlow::setValues(list, *mSymbolDatabase, mErrorLogger, mSettings, mTimerResults);
} else {
ValueFlow::setValues(list, *mSymbolDatabase, *mErrorLogger, mSettings, mTimerResults);
ValueFlow::setValues(list, *mSymbolDatabase, mErrorLogger, mSettings, mTimerResults);
}

arraySizeAfterValueFlow();
Expand Down Expand Up @@ -10428,10 +10427,7 @@ void Tokenizer::reportError(const Token* tok, const Severity severity, const std
void Tokenizer::reportError(const std::list<const Token*>& callstack, Severity severity, const std::string& id, const std::string& msg, bool inconclusive) const
{
const ErrorMessage errmsg(callstack, &list, severity, id, msg, inconclusive ? Certainty::inconclusive : Certainty::normal);
if (mErrorLogger)
mErrorLogger->reportErr(errmsg);
else
Check::writeToErrorList(errmsg);
mErrorLogger.reportErr(errmsg);
}

void Tokenizer::setPodTypes()
Expand Down
4 changes: 2 additions & 2 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class CPPCHECKLIB Tokenizer {
friend class TestTokenizer;

public:
explicit Tokenizer(const Settings & settings, ErrorLogger *errorLogger);
explicit Tokenizer(const Settings & settings, ErrorLogger &errorLogger);
~Tokenizer();

void setTimerResults(TimerResults *tr) {
Expand Down Expand Up @@ -645,7 +645,7 @@ class CPPCHECKLIB Tokenizer {
const Settings & mSettings;

/** errorlogger */
ErrorLogger* const mErrorLogger;
ErrorLogger& mErrorLogger;

/** Symbol database that all checks etc can use */
SymbolDatabase* mSymbolDatabase{};
Expand Down
Loading
Loading