Skip to content

Commit 628b894

Browse files
committed
pass ErrorLogger by reference into SymbolDatabase
1 parent b9c535c commit 628b894

3 files changed

Lines changed: 18 additions & 17 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#include <unordered_set>
5353
//---------------------------------------------------------------------------
5454

55-
SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger* errorLogger)
55+
SymbolDatabase::SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger& errorLogger)
5656
: mTokenizer(tokenizer), mSettings(settings), mErrorLogger(errorLogger)
5757
{
5858
if (!mTokenizer.tokens())
@@ -169,10 +169,9 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes()
169169
// find all scopes
170170
for (const Token *tok = mTokenizer.tokens(); tok; tok = tok ? tok->next() : nullptr) {
171171
// #5593 suggested to add here:
172-
if (mErrorLogger)
173-
mErrorLogger->reportProgress(mTokenizer.list.getSourceFilePath(),
174-
"SymbolDatabase",
175-
tok->progressValue());
172+
mErrorLogger.reportProgress(mTokenizer.list.getSourceFilePath(),
173+
"SymbolDatabase",
174+
tok->progressValue());
176175
// Locate next class
177176
if ((tok->isCpp() && tok->isKeyword() &&
178177
((Token::Match(tok, "class|struct|union|namespace ::| %name% final| {|:|::|<") &&
@@ -2087,14 +2086,14 @@ void SymbolDatabase::validateExecutableScopes() const
20872086
for (std::size_t i = 0; i < functions; ++i) {
20882087
const Scope* const scope = functionScopes[i];
20892088
const Function* const function = scope->function;
2090-
if (mErrorLogger && scope->isExecutable() && !function) {
2089+
if (scope->isExecutable() && !function) {
20912090
const std::list<const Token*> callstack(1, scope->classDef);
20922091
const std::string msg = std::string("Executable scope '") + scope->classDef->str() + "' with unknown function.";
20932092
const ErrorMessage errmsg(callstack, &mTokenizer.list, Severity::debug,
20942093
"symbolDatabaseWarning",
20952094
msg,
20962095
Certainty::normal);
2097-
mErrorLogger->reportErr(errmsg);
2096+
mErrorLogger.reportErr(errmsg);
20982097
}
20992098
}
21002099
}
@@ -2152,7 +2151,7 @@ void SymbolDatabase::debugSymbolDatabase() const
21522151
for (const Token* tok = mTokenizer.list.front(); tok != mTokenizer.list.back(); tok = tok->next()) {
21532152
if (tok->astParent() && tok->astParent()->getTokenDebug() == tok->getTokenDebug())
21542153
continue;
2155-
if (mErrorLogger && tok->getTokenDebug() == TokenDebug::ValueType) {
2154+
if (tok->getTokenDebug() == TokenDebug::ValueType) {
21562155

21572156
std::string msg = "Value type is ";
21582157
ErrorPath errorPath;
@@ -2164,7 +2163,7 @@ void SymbolDatabase::debugSymbolDatabase() const
21642163
msg += "missing";
21652164
}
21662165
errorPath.emplace_back(tok, "");
2167-
mErrorLogger->reportErr(
2166+
mErrorLogger.reportErr(
21682167
{errorPath, &mTokenizer.list, Severity::debug, "valueType", msg, CWE{0}, Certainty::normal});
21692168
}
21702169
}
@@ -3584,27 +3583,27 @@ std::string Type::name() const
35843583

35853584
void SymbolDatabase::debugMessage(const Token *tok, const std::string &type, const std::string &msg) const
35863585
{
3587-
if (tok && mSettings.debugwarnings && mErrorLogger) {
3586+
if (tok && mSettings.debugwarnings) {
35883587
const std::list<const Token*> locationList(1, tok);
35893588
const ErrorMessage errmsg(locationList, &mTokenizer.list,
35903589
Severity::debug,
35913590
type,
35923591
msg,
35933592
Certainty::normal);
3594-
mErrorLogger->reportErr(errmsg);
3593+
mErrorLogger.reportErr(errmsg);
35953594
}
35963595
}
35973596

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

lib/symboldatabase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ class CPPCHECKLIB ValueType {
13191319
class CPPCHECKLIB SymbolDatabase {
13201320
friend class TestSymbolDatabase;
13211321
public:
1322-
SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger* errorLogger);
1322+
SymbolDatabase(Tokenizer& tokenizer, const Settings& settings, ErrorLogger& errorLogger);
13231323
~SymbolDatabase();
13241324

13251325
/** @brief Information about all namespaces/classes/structures */
@@ -1467,7 +1467,7 @@ class CPPCHECKLIB SymbolDatabase {
14671467

14681468
Tokenizer& mTokenizer;
14691469
const Settings &mSettings;
1470-
ErrorLogger *mErrorLogger;
1470+
ErrorLogger &mErrorLogger;
14711471

14721472
/** variable symbol table */
14731473
std::vector<const Variable *> mVariableList;

lib/tokenize.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9987,8 +9987,10 @@ void Tokenizer::simplifyBorland()
99879987

99889988
void Tokenizer::createSymbolDatabase()
99899989
{
9990-
if (!mSymbolDatabase)
9991-
mSymbolDatabase = new SymbolDatabase(*this, mSettings, mErrorLogger);
9990+
if (!mSymbolDatabase) {
9991+
assert(mErrorLogger != nullptr);
9992+
mSymbolDatabase = new SymbolDatabase(*this, mSettings, *mErrorLogger);
9993+
}
99929994
mSymbolDatabase->validate();
99939995
}
99949996

0 commit comments

Comments
 (0)