Skip to content

Commit c6f4820

Browse files
committed
CppCheck: small cleanup
1 parent 4ffee84 commit c6f4820

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

lib/cppcheck.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,6 @@ unsigned int CppCheck::check(const FileSettings &fs)
850850
return returnValue;
851851
}
852852

853-
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fileIndex, const uint8_t* data, std::size_t size)
854-
{
855-
return checkInternal(file, cfgname, fileIndex,
856-
[&file, data, size](std::vector<std::string>& files) {
857-
return simplecpp::TokenList{data, size, files, file.spath()};
858-
},
859-
[&file, data, size](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
860-
return simplecpp::TokenList{data, size, files, file.spath(), outputList};
861-
});
862-
}
863-
864853
std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens, const std::string& filePath) const
865854
{
866855
std::ostringstream toolinfo;
@@ -882,18 +871,23 @@ std::size_t CppCheck::calculateHash(const Preprocessor& preprocessor, const simp
882871
return preprocessor.calculateHash(tokens, toolinfo.str());
883872
}
884873

874+
unsigned int CppCheck::checkBuffer(const FileWithDetails &file, const std::string &cfgname, int fileIndex, const uint8_t* data, std::size_t size)
875+
{
876+
const auto f = [&file, data, size](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
877+
return simplecpp::TokenList{data, size, files, file.spath(), outputList};
878+
};
879+
return checkInternal(file, cfgname, fileIndex, f);
880+
}
881+
885882
unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname, int fileIndex)
886883
{
887-
return checkInternal(file, cfgname, fileIndex,
888-
[&file](std::vector<std::string>& files) {
889-
return simplecpp::TokenList{file.spath(), files};
890-
},
891-
[&file](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
884+
const auto f = [&file](std::vector<std::string>& files, simplecpp::OutputList* outputList) {
892885
return simplecpp::TokenList{file.spath(), files, outputList};
893-
});
886+
};
887+
return checkInternal(file, cfgname, fileIndex, f);
894888
}
895889

896-
unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokensFn& createTokens, const CreateTokenListFn& createTokenList)
890+
unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokenListFn& createTokenList)
897891
{
898892
// TODO: move to constructor when CppCheck no longer owns the settings
899893
if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck)
@@ -945,7 +939,7 @@ unsigned int CppCheck::checkInternal(const FileWithDetails& file, const std::str
945939
// markup files are special and do not adhere to the enforced language
946940
TokenList tokenlist{mSettings, Standards::Language::C};
947941
std::vector<std::string> files;
948-
simplecpp::TokenList tokens = createTokens(files);
942+
simplecpp::TokenList tokens = createTokenList(files, nullptr);
949943
if (analyzerInformation) {
950944
const Preprocessor preprocessor(mSettings, mErrorLogger, file.lang());
951945
hash = calculateHash(preprocessor, tokens);

lib/cppcheck.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,17 @@ class CPPCHECKLIB CppCheck {
196196
*/
197197
unsigned int checkBuffer(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const uint8_t* data, std::size_t size);
198198

199-
using CreateTokensFn = std::function<simplecpp::TokenList (std::vector<std::string>& files)>;
200199
// TODO: should use simplecpp::OutputList
201200
using CreateTokenListFn = std::function<simplecpp::TokenList (std::vector<std::string>&, std::list<simplecpp::Output>*)>;
202201

203202
/**
204203
* @brief Check a file using stream
205204
* @param file the file
206205
* @param cfgname cfg name
207-
* @param createTokens a function to create the tokens with
208-
* @param createTokenList a function to create the TokenList with
206+
* @param createTokenList a function to create the simplecpp::TokenList with
209207
* @return number of errors found
210208
*/
211-
unsigned int checkInternal(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokensFn& createTokens, const CreateTokenListFn& createTokenList);
209+
unsigned int checkInternal(const FileWithDetails& file, const std::string &cfgname, int fileIndex, const CreateTokenListFn& createTokenList);
212210

213211
/**
214212
* @brief Check normal tokens

0 commit comments

Comments
 (0)