Skip to content

Commit 5900421

Browse files
committed
CppCheck: calculate proper hash for markup file analyzer information [skip ci]
1 parent 7b31ad8 commit 5900421

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/cppcheck.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -680,21 +680,27 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
680680
try {
681681
if (mSettings.library.markupFile(file.spath())) {
682682
if (mUnusedFunctionsCheck && (mSettings.useSingleJob() || !mSettings.buildDir.empty())) {
683+
std::size_t hash;
683684
// this is not a real source file - we just want to tokenize it. treat it as C anyways as the language needs to be determined.
684685
Tokenizer tokenizer(mSettings, *this);
685686
// enforce the language since markup files are special and do not adhere to the enforced language
686687
tokenizer.list.setLang(Standards::Language::C, true);
687688
if (fileStream) {
688-
tokenizer.list.createTokens(*fileStream, file.spath());
689+
std::vector<std::string> files{file.spath()};
690+
simplecpp::TokenList tokens(*fileStream, files);
691+
const Preprocessor preprocessor(mSettings, *this);
692+
hash = calculateHash(preprocessor, tokens, mSettings);
693+
tokenizer.list.createTokens(std::move(tokens));
689694
}
690695
else {
691-
std::ifstream in(file.spath());
692-
tokenizer.list.createTokens(in, file.spath());
696+
std::vector<std::string> files{file.spath()};
697+
simplecpp::TokenList tokens(file.spath(), files);
698+
const Preprocessor preprocessor(mSettings, *this);
699+
hash = calculateHash(preprocessor, tokens, mSettings);
700+
tokenizer.list.createTokens(std::move(tokens));
693701
}
694702
mUnusedFunctionsCheck->parseTokens(tokenizer, mSettings);
695703

696-
// TODO: how to get the proper tokenlist to generate the proper hash?
697-
const std::size_t hash = time(nullptr); // calculateHash(tokenizer.list, mSettings);
698704
std::list<ErrorMessage> errors;
699705
mAnalyzerInformation.analyzeFile(mSettings.buildDir, file.spath(), cfgname, hash, errors);
700706
mAnalyzerInformation.setFileInfo("CheckUnusedFunctions", mUnusedFunctionsCheck->analyzerInfo());

0 commit comments

Comments
 (0)