Refactoring CheckUnusedFunctions so it uses new infrastructure for multifile analysis
This commit is contained in:
parent
cf3f8c2f38
commit
0b9d80c95d
|
@ -790,8 +790,6 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
|||
c++;
|
||||
}
|
||||
}
|
||||
|
||||
cppcheck.checkFunctionUsage();
|
||||
cppcheck.analyseWholeProgram();
|
||||
} else if (!ThreadExecutor::isEnabled()) {
|
||||
std::cout << "No thread support yet implemented for this platform." << std::endl;
|
||||
|
|
|
@ -91,8 +91,9 @@ public:
|
|||
virtual ~FileInfo() {}
|
||||
};
|
||||
|
||||
virtual FileInfo * getFileInfo(const Tokenizer *tokenizer) const {
|
||||
virtual FileInfo * getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const {
|
||||
(void)tokenizer;
|
||||
(void)settings;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -1805,8 +1805,10 @@ void CheckBufferOverrun::writeOutsideBufferSizeError(const Token *tok, const std
|
|||
" Please check the second and the third parameter of the function '"+strFunctionName+"'.");
|
||||
}
|
||||
|
||||
Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer) const
|
||||
Check::FileInfo* CheckBufferOverrun::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
|
||||
{
|
||||
(void)settings;
|
||||
|
||||
MyFileInfo *fileInfo = new MyFileInfo;
|
||||
|
||||
// Array usage..
|
||||
|
|
|
@ -220,10 +220,10 @@ public:
|
|||
};
|
||||
|
||||
/** @brief Parse current TU and extract file info */
|
||||
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer) const;
|
||||
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
|
||||
|
||||
/** @brief Analyse all file infos for all TU */
|
||||
virtual void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
|
||||
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -1013,8 +1013,9 @@ public:
|
|||
/// @}
|
||||
|
||||
|
||||
Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer *tokenizer) const
|
||||
Check::FileInfo *CheckUninitVar::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
|
||||
{
|
||||
(void)settings;
|
||||
MyFileInfo * mfi = new MyFileInfo;
|
||||
analyseFunctions(tokenizer, mfi->uvarFunctions);
|
||||
// TODO: add suspicious function calls
|
||||
|
|
|
@ -80,10 +80,10 @@ public:
|
|||
};
|
||||
|
||||
/** @brief Parse current TU and extract file info */
|
||||
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer) const;
|
||||
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
|
||||
|
||||
/** @brief Analyse all file infos for all TU */
|
||||
virtual void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
|
||||
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
|
||||
|
||||
void analyseFunctions(const Tokenizer *tokenizer, std::set<std::string> &f) const;
|
||||
|
||||
|
|
|
@ -263,3 +263,17 @@ void CheckUnusedFunctions::unusedFunctionError(ErrorLogger * const errorLogger,
|
|||
else
|
||||
reportError(errmsg);
|
||||
}
|
||||
|
||||
Check::FileInfo *CheckUnusedFunctions::getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const
|
||||
{
|
||||
if (settings->isEnabled("unusedFunction") && settings->_jobs == 1)
|
||||
instance.parseTokens(*tokenizer, tokenizer->list.getFiles().front().c_str(), settings);
|
||||
return nullptr;
|
||||
|
||||
}
|
||||
|
||||
void CheckUnusedFunctions::analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger)
|
||||
{
|
||||
(void)fileInfo;
|
||||
instance.check(&errorLogger);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,12 @@ public:
|
|||
|
||||
void check(ErrorLogger * const errorLogger);
|
||||
|
||||
/** @brief Parse current TU and extract file info */
|
||||
Check::FileInfo *getFileInfo(const Tokenizer *tokenizer, const Settings *settings) const;
|
||||
|
||||
/** @brief Analyse all file infos for all TU */
|
||||
void analyseWholeProgram(const std::list<Check::FileInfo*> &fileInfo, ErrorLogger &errorLogger);
|
||||
|
||||
static CheckUnusedFunctions instance;
|
||||
|
||||
private:
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
#include "preprocessor.h" // Preprocessor
|
||||
#include "tokenize.h" // Tokenizer
|
||||
#include "checkunusedfunctions.h"
|
||||
|
||||
#include "check.h"
|
||||
#include "path.h"
|
||||
|
@ -278,23 +277,6 @@ void CppCheck::internalError(const std::string &filename, const std::string &msg
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void CppCheck::checkFunctionUsage()
|
||||
{
|
||||
// This generates false positives - especially for libraries
|
||||
if (_settings.isEnabled("unusedFunction") && _settings._jobs == 1) {
|
||||
const bool verbose_orig = _settings._verbose;
|
||||
_settings._verbose = false;
|
||||
|
||||
if (_settings._errorsOnly == false)
|
||||
_errorLogger.reportOut("Checking usage of global functions..");
|
||||
|
||||
CheckUnusedFunctions::instance.check(this);
|
||||
|
||||
_settings._verbose = verbose_orig;
|
||||
}
|
||||
}
|
||||
|
||||
void CppCheck::analyseFile(std::istream &fin, const std::string &filename)
|
||||
{
|
||||
// Preprocess file..
|
||||
|
@ -379,8 +361,12 @@ bool CppCheck::checkFile(const std::string &code, const char FileName[], std::se
|
|||
(*it)->runChecks(&_tokenizer, &_settings, this);
|
||||
}
|
||||
|
||||
if (_settings.isEnabled("unusedFunction") && _settings._jobs == 1)
|
||||
CheckUnusedFunctions::instance.parseTokens(_tokenizer, FileName, &_settings);
|
||||
// Analyse the tokens..
|
||||
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
|
||||
Check::FileInfo *fi = (*it)->getFileInfo(&_tokenizer, &_settings);
|
||||
if (fi != nullptr)
|
||||
fileInfo.push_back(fi);
|
||||
}
|
||||
|
||||
executeRules("normal", _tokenizer);
|
||||
|
||||
|
@ -402,13 +388,6 @@ bool CppCheck::checkFile(const std::string &code, const char FileName[], std::se
|
|||
(*it)->runSimplifiedChecks(&_tokenizer, &_settings, this);
|
||||
}
|
||||
|
||||
// Analyse the tokens..
|
||||
for (std::list<Check *>::const_iterator it = Check::instances().begin(); it != Check::instances().end(); ++it) {
|
||||
Check::FileInfo *fi = (*it)->getFileInfo(&_tokenizer);
|
||||
if (fi != nullptr)
|
||||
fileInfo.push_back(fi);
|
||||
}
|
||||
|
||||
if (_settings.terminated())
|
||||
return true;
|
||||
|
||||
|
|
|
@ -82,12 +82,6 @@ public:
|
|||
*/
|
||||
unsigned int check(const std::string &path, const std::string &content);
|
||||
|
||||
/**
|
||||
* @brief Check function usage.
|
||||
* @note Call this after all files has been checked
|
||||
*/
|
||||
void checkFunctionUsage();
|
||||
|
||||
/**
|
||||
* @brief Get reference to current settings.
|
||||
* @return a reference to current settings
|
||||
|
|
Loading…
Reference in New Issue