2121#include " checkunusedfunctions.h"
2222
2323#include " astutils.h"
24- #include " check.h"
2524#include " errorlogger.h"
2625#include " errortypes.h"
2726#include " library.h"
@@ -75,9 +74,9 @@ void CheckUnusedFunctions::clear()
7574 instance.mFunctionCalls .clear ();
7675}
7776
78- void CheckUnusedFunctions::parseTokens (const Tokenizer &tokenizer, const char FileName[], const Settings * settings)
77+ void CheckUnusedFunctions::parseTokens (const Tokenizer &tokenizer, const char FileName[], const Settings & settings)
7978{
80- const bool doMarkup = settings-> library .markupFile (FileName);
79+ const bool doMarkup = settings. library .markupFile (FileName);
8180
8281 // Function declarations..
8382 if (!doMarkup) {
@@ -126,21 +125,21 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
126125 lambdaEndToken = findLambdaEndToken (tok);
127126
128127 // parsing of library code to find called functions
129- if (settings-> library .isexecutableblock (FileName, tok->str ())) {
130- const Token * markupVarToken = tok->tokAt (settings-> library .blockstartoffset (FileName));
128+ if (settings. library .isexecutableblock (FileName, tok->str ())) {
129+ const Token * markupVarToken = tok->tokAt (settings. library .blockstartoffset (FileName));
131130 // not found
132131 if (!markupVarToken)
133132 continue ;
134133 int scope = 0 ;
135134 bool start = true ;
136135 // find all function calls in library code (starts with '(', not if or while etc)
137136 while ((scope || start) && markupVarToken) {
138- if (markupVarToken->str () == settings-> library .blockstart (FileName)) {
137+ if (markupVarToken->str () == settings. library .blockstart (FileName)) {
139138 scope++;
140139 start = false ;
141- } else if (markupVarToken->str () == settings-> library .blockend (FileName))
140+ } else if (markupVarToken->str () == settings. library .blockend (FileName))
142141 scope--;
143- else if (!settings-> library .iskeyword (FileName, markupVarToken->str ())) {
142+ else if (!settings. library .iskeyword (FileName, markupVarToken->str ())) {
144143 mFunctionCalls .insert (markupVarToken->str ());
145144 if (mFunctions .find (markupVarToken->str ()) != mFunctions .end ())
146145 mFunctions [markupVarToken->str ()].usedOtherFile = true ;
@@ -158,18 +157,18 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
158157 }
159158
160159 if (!doMarkup // only check source files
161- && settings-> library .isexporter (tok->str ()) && tok->next () != nullptr ) {
160+ && settings. library .isexporter (tok->str ()) && tok->next () != nullptr ) {
162161 const Token * propToken = tok->next ();
163162 while (propToken && propToken->str () != " )" ) {
164- if (settings-> library .isexportedprefix (tok->str (), propToken->str ())) {
163+ if (settings. library .isexportedprefix (tok->str (), propToken->str ())) {
165164 const Token* nextPropToken = propToken->next ();
166165 const std::string& value = nextPropToken->str ();
167166 if (mFunctions .find (value) != mFunctions .end ()) {
168167 mFunctions [value].usedOtherFile = true ;
169168 }
170169 mFunctionCalls .insert (value);
171170 }
172- if (settings-> library .isexportedsuffix (tok->str (), propToken->str ())) {
171+ if (settings. library .isexportedsuffix (tok->str (), propToken->str ())) {
173172 const Token* prevPropToken = propToken->previous ();
174173 const std::string& value = prevPropToken->str ();
175174 if (value != " )" && mFunctions .find (value) != mFunctions .end ()) {
@@ -181,7 +180,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
181180 }
182181 }
183182
184- if (doMarkup && settings-> library .isimporter (FileName, tok->str ()) && tok->next ()) {
183+ if (doMarkup && settings. library .isimporter (FileName, tok->str ()) && tok->next ()) {
185184 const Token * propToken = tok->next ();
186185 if (propToken->next ()) {
187186 propToken = propToken->next ();
@@ -197,8 +196,8 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
197196 }
198197 }
199198
200- if (settings-> library .isreflection (tok->str ())) {
201- const int argIndex = settings-> library .reflectionArgument (tok->str ());
199+ if (settings. library .isreflection (tok->str ())) {
200+ const int argIndex = settings. library .reflectionArgument (tok->str ());
202201 if (argIndex >= 0 ) {
203202 const Token * funcToken = tok->next ();
204203 int index = 0 ;
@@ -320,7 +319,7 @@ static bool isOperatorFunction(const std::string & funcName)
320319 return std::find (additionalOperators.cbegin (), additionalOperators.cend (), funcName.substr (operatorPrefix.length ())) != additionalOperators.cend ();
321320}
322321
323- bool CheckUnusedFunctions::check (ErrorLogger * const errorLogger, const Settings& settings) const
322+ bool CheckUnusedFunctions::check (ErrorLogger& errorLogger, const Settings& settings) const
324323{
325324 using ErrorParams = std::tuple<std::string, unsigned int , unsigned int , std::string>;
326325 std::vector<ErrorParams> errors; // ensure well-defined order
@@ -354,7 +353,7 @@ bool CheckUnusedFunctions::check(ErrorLogger * const errorLogger, const Settings
354353 return !errors.empty ();
355354}
356355
357- void CheckUnusedFunctions::unusedFunctionError (ErrorLogger * const errorLogger,
356+ void CheckUnusedFunctions::unusedFunctionError (ErrorLogger& errorLogger,
358357 const std::string &filename, unsigned int fileIndex, unsigned int lineNumber,
359358 const std::string &funcname)
360359{
@@ -365,26 +364,23 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
365364 }
366365
367366 const ErrorMessage errmsg (locationList, emptyString, Severity::style, " $symbol:" + funcname + " \n The function '$symbol' is never used." , " unusedFunction" , CWE561, Certainty::normal);
368- if (errorLogger)
369- errorLogger->reportErr (errmsg);
370- else
371- Check::writeToErrorList (errmsg);
367+ errorLogger.reportErr (errmsg);
372368}
373369
374- void CheckUnusedFunctions::parseTokens (const Tokenizer * tokenizer, const Settings * settings)
370+ void CheckUnusedFunctions::parseTokens (const Tokenizer & tokenizer, const Settings & settings)
375371{
376- if (!settings-> checks .isEnabled (Checks::unusedFunction))
372+ if (!settings. checks .isEnabled (Checks::unusedFunction))
377373 return ;
378- if (settings-> useSingleJob () && settings-> buildDir .empty ())
379- instance.parseTokens (* tokenizer, tokenizer-> list .getFiles ().front ().c_str (), settings);
374+ if (settings. useSingleJob () && settings. buildDir .empty ())
375+ instance.parseTokens (tokenizer, tokenizer. list .getFiles ().front ().c_str (), settings);
380376}
381377
382378bool CheckUnusedFunctions::check (const Settings& settings, ErrorLogger &errorLogger)
383379{
384380 // TODO
385381 // CheckUnusedFunctions dummy(nullptr, &settings, &errorLogger);
386382 // dummy.logChecker("CheckUnusedFunctions::analyseWholeProgram");
387- return instance.check (& errorLogger, settings);
383+ return instance.check (errorLogger, settings);
388384}
389385
390386CheckUnusedFunctions::FunctionDecl::FunctionDecl (const Function *f)
@@ -414,7 +410,7 @@ namespace {
414410 };
415411}
416412
417- void CheckUnusedFunctions::analyseWholeProgram (const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir)
413+ void CheckUnusedFunctions::analyseWholeProgram (const Settings &settings, ErrorLogger & errorLogger, const std::string &buildDir)
418414{
419415 std::map<std::string, Location> decls;
420416 std::set<std::string> calls;
0 commit comments