Skip to content

Commit ee3d733

Browse files
committed
CppCheck: calculate proper hash for markup file analyzer information
1 parent 4e8e0a5 commit ee3d733

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: lib/cppcheck.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -676,21 +676,27 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
676676
try {
677677
if (mSettings.library.markupFile(file.spath())) {
678678
if (mUnusedFunctionsCheck && (mSettings.useSingleJob() || !mSettings.buildDir.empty())) {
679+
std::size_t hash;
679680
// 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.
680681
Tokenizer tokenizer(mSettings, *this);
681682
// enforce the language since markup files are special and do not adhere to the enforced language
682683
tokenizer.list.setLang(Standards::Language::C, true);
683684
if (fileStream) {
684-
tokenizer.list.createTokens(*fileStream, file.spath());
685+
std::vector<std::string> files{file.spath()};
686+
simplecpp::TokenList tokens(*fileStream, files);
687+
const Preprocessor preprocessor(mSettings, *this);
688+
hash = calculateHash(preprocessor, tokens, mSettings);
689+
tokenizer.list.createTokens(std::move(tokens));
685690
}
686691
else {
687-
std::ifstream in(file.spath());
688-
tokenizer.list.createTokens(in, file.spath());
692+
std::vector<std::string> files{file.spath()};
693+
simplecpp::TokenList tokens(file.spath(), files);
694+
const Preprocessor preprocessor(mSettings, *this);
695+
hash = calculateHash(preprocessor, tokens, mSettings);
696+
tokenizer.list.createTokens(std::move(tokens));
689697
}
690698
mUnusedFunctionsCheck->parseTokens(tokenizer, mSettings);
691699

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

0 commit comments

Comments
 (0)