@@ -74,9 +74,9 @@ void CheckUnusedFunctions::clear()
7474 instance.mFunctionCalls .clear ();
7575}
7676
77- 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)
7878{
79- const bool doMarkup = settings-> library .markupFile (FileName);
79+ const bool doMarkup = settings. library .markupFile (FileName);
8080
8181 // Function declarations..
8282 if (!doMarkup) {
@@ -125,21 +125,21 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
125125 lambdaEndToken = findLambdaEndToken (tok);
126126
127127 // parsing of library code to find called functions
128- if (settings-> library .isexecutableblock (FileName, tok->str ())) {
129- 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));
130130 // not found
131131 if (!markupVarToken)
132132 continue ;
133133 int scope = 0 ;
134134 bool start = true ;
135135 // find all function calls in library code (starts with '(', not if or while etc)
136136 while ((scope || start) && markupVarToken) {
137- if (markupVarToken->str () == settings-> library .blockstart (FileName)) {
137+ if (markupVarToken->str () == settings. library .blockstart (FileName)) {
138138 scope++;
139139 start = false ;
140- } else if (markupVarToken->str () == settings-> library .blockend (FileName))
140+ } else if (markupVarToken->str () == settings. library .blockend (FileName))
141141 scope--;
142- else if (!settings-> library .iskeyword (FileName, markupVarToken->str ())) {
142+ else if (!settings. library .iskeyword (FileName, markupVarToken->str ())) {
143143 mFunctionCalls .insert (markupVarToken->str ());
144144 if (mFunctions .find (markupVarToken->str ()) != mFunctions .end ())
145145 mFunctions [markupVarToken->str ()].usedOtherFile = true ;
@@ -157,18 +157,18 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
157157 }
158158
159159 if (!doMarkup // only check source files
160- && settings-> library .isexporter (tok->str ()) && tok->next () != nullptr ) {
160+ && settings. library .isexporter (tok->str ()) && tok->next () != nullptr ) {
161161 const Token * propToken = tok->next ();
162162 while (propToken && propToken->str () != " )" ) {
163- if (settings-> library .isexportedprefix (tok->str (), propToken->str ())) {
163+ if (settings. library .isexportedprefix (tok->str (), propToken->str ())) {
164164 const Token* nextPropToken = propToken->next ();
165165 const std::string& value = nextPropToken->str ();
166166 if (mFunctions .find (value) != mFunctions .end ()) {
167167 mFunctions [value].usedOtherFile = true ;
168168 }
169169 mFunctionCalls .insert (value);
170170 }
171- if (settings-> library .isexportedsuffix (tok->str (), propToken->str ())) {
171+ if (settings. library .isexportedsuffix (tok->str (), propToken->str ())) {
172172 const Token* prevPropToken = propToken->previous ();
173173 const std::string& value = prevPropToken->str ();
174174 if (value != " )" && mFunctions .find (value) != mFunctions .end ()) {
@@ -180,7 +180,7 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
180180 }
181181 }
182182
183- if (doMarkup && settings-> library .isimporter (FileName, tok->str ()) && tok->next ()) {
183+ if (doMarkup && settings. library .isimporter (FileName, tok->str ()) && tok->next ()) {
184184 const Token * propToken = tok->next ();
185185 if (propToken->next ()) {
186186 propToken = propToken->next ();
@@ -196,8 +196,8 @@ void CheckUnusedFunctions::parseTokens(const Tokenizer &tokenizer, const char Fi
196196 }
197197 }
198198
199- if (settings-> library .isreflection (tok->str ())) {
200- const int argIndex = settings-> library .reflectionArgument (tok->str ());
199+ if (settings. library .isreflection (tok->str ())) {
200+ const int argIndex = settings. library .reflectionArgument (tok->str ());
201201 if (argIndex >= 0 ) {
202202 const Token * funcToken = tok->next ();
203203 int index = 0 ;
@@ -319,7 +319,7 @@ static bool isOperatorFunction(const std::string & funcName)
319319 return std::find (additionalOperators.cbegin (), additionalOperators.cend (), funcName.substr (operatorPrefix.length ())) != additionalOperators.cend ();
320320}
321321
322- bool CheckUnusedFunctions::check (ErrorLogger * const errorLogger, const Settings& settings) const
322+ bool CheckUnusedFunctions::check (ErrorLogger& errorLogger, const Settings& settings) const
323323{
324324 using ErrorParams = std::tuple<std::string, unsigned int , unsigned int , std::string>;
325325 std::vector<ErrorParams> errors; // ensure well-defined order
@@ -353,7 +353,7 @@ bool CheckUnusedFunctions::check(ErrorLogger * const errorLogger, const Settings
353353 return !errors.empty ();
354354}
355355
356- void CheckUnusedFunctions::unusedFunctionError (ErrorLogger * const errorLogger,
356+ void CheckUnusedFunctions::unusedFunctionError (ErrorLogger& errorLogger,
357357 const std::string &filename, unsigned int fileIndex, unsigned int lineNumber,
358358 const std::string &funcname)
359359{
@@ -364,29 +364,27 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
364364 }
365365
366366 const ErrorMessage errmsg (std::move (locationList), emptyString, Severity::style, " $symbol:" + funcname + " \n The function '$symbol' is never used." , " unusedFunction" , CWE561, Certainty::normal);
367- if (errorLogger)
368- errorLogger->reportErr (errmsg);
369- else
370- Check::writeToErrorList (errmsg);
367+ errorLogger.reportErr (errmsg);
371368}
372369
373- Check::FileInfo * CheckUnusedFunctions::getFileInfo (const Tokenizer * tokenizer, const Settings * settings) const
370+ void CheckUnusedFunctions::parseTokens (const Tokenizer & tokenizer, const Settings & settings)
374371{
375- if (!settings->checks .isEnabled (Checks::unusedFunction))
376- return nullptr ;
377- if (settings->useSingleJob () && settings->buildDir .empty ())
378- instance.parseTokens (*tokenizer, tokenizer->list .getFiles ().front ().c_str (), settings);
379- return nullptr ;
372+ if (!settings.checks .isEnabled (Checks::unusedFunction))
373+ return ;
374+ if (settings.useSingleJob () && settings.buildDir .empty ())
375+ instance.parseTokens (tokenizer, tokenizer.list .getFiles ().front ().c_str (), settings);
380376}
381377
382- bool CheckUnusedFunctions::analyseWholeProgram (const CTU::FileInfo *ctu, const std::list<Check::FileInfo*> &fileInfo, const Settings& settings, ErrorLogger &errorLogger)
378+ #define logChecker (id ) \
379+ do { \
380+ const ErrorMessage errmsg ({}, nullptr , Severity::internal, " logChecker" , (id), CWE (0U ), Certainty::normal); \
381+ errorLogger.reportErr (errmsg); \
382+ } while (false )
383+
384+ bool CheckUnusedFunctions::check (const Settings& settings, ErrorLogger &errorLogger)
383385{
384- (void )ctu;
385- (void )fileInfo;
386- CheckUnusedFunctions dummy (nullptr , &settings, &errorLogger);
387- dummy.
388- logChecker (" CheckUnusedFunctions::analyseWholeProgram" ); // unusedFunctions
389- return check (&errorLogger, settings);
386+ logChecker (" CheckUnusedFunctions::check" ); // unusedFunction
387+ return instance.check (errorLogger, settings);
390388}
391389
392390CheckUnusedFunctions::FunctionDecl::FunctionDecl (const Function *f)
@@ -416,7 +414,7 @@ namespace {
416414 };
417415}
418416
419- void CheckUnusedFunctions::analyseWholeProgram (const Settings &settings, ErrorLogger * const errorLogger, const std::string &buildDir)
417+ void CheckUnusedFunctions::analyseWholeProgram (const Settings &settings, ErrorLogger & errorLogger, const std::string &buildDir)
420418{
421419 std::map<std::string, Location> decls;
422420 std::set<std::string> calls;
0 commit comments