Skip to content

Commit

Permalink
pass ErrorLogger by reference into SymbolDatabase
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Apr 11, 2024
1 parent b9c535c commit 628b894
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
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
6 changes: 4 additions & 2 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9987,8 +9987,10 @@ void Tokenizer::simplifyBorland()

void Tokenizer::createSymbolDatabase()
{
if (!mSymbolDatabase)
mSymbolDatabase = new SymbolDatabase(*this, mSettings, mErrorLogger);
if (!mSymbolDatabase) {
assert(mErrorLogger != nullptr);
mSymbolDatabase = new SymbolDatabase(*this, mSettings, *mErrorLogger);
}
mSymbolDatabase->validate();
}

Expand Down

0 comments on commit 628b894

Please sign in to comment.