Skip to content

Commit 48283a4

Browse files
committed
CppCheck: calculate proper hash for markup file analyzer information
1 parent 47b3e62 commit 48283a4

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Diff for: lib/cppcheck.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -683,22 +683,32 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
683683
mAnalyzerInformation.reset(new AnalyzerInformation);
684684

685685
if (mUnusedFunctionsCheck && (mSettings.useSingleJob() || mAnalyzerInformation)) {
686+
std::size_t hash = 0;
686687
// 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.
687688
Tokenizer tokenizer(mSettings, *this);
688689
// enforce the language since markup files are special and do not adhere to the enforced language
689690
tokenizer.list.setLang(Standards::Language::C, true);
690691
if (fileStream) {
691-
tokenizer.list.createTokens(*fileStream, file.spath());
692+
std::vector<std::string> files{file.spath()};
693+
simplecpp::TokenList tokens(*fileStream, files);
694+
if (mAnalyzerInformation) {
695+
const Preprocessor preprocessor(mSettings, *this);
696+
hash = calculateHash(preprocessor, tokens, mSettings);
697+
}
698+
tokenizer.list.createTokens(std::move(tokens));
692699
}
693700
else {
694-
std::ifstream in(file.spath());
695-
tokenizer.list.createTokens(in, file.spath());
701+
std::vector<std::string> files{file.spath()};
702+
simplecpp::TokenList tokens(file.spath(), files);
703+
if (mAnalyzerInformation) {
704+
const Preprocessor preprocessor(mSettings, *this);
705+
hash = calculateHash(preprocessor, tokens, mSettings);
706+
}
707+
tokenizer.list.createTokens(std::move(tokens));
696708
}
697709
mUnusedFunctionsCheck->parseTokens(tokenizer, mSettings);
698710

699711
if (mAnalyzerInformation) {
700-
// TODO: how to get the proper tokenlist to generate the proper hash?
701-
const std::size_t hash = time(nullptr); // calculateHash(tokenizer.list, mSettings);
702712
std::list<ErrorMessage> errors;
703713
mAnalyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, hash, errors);
704714
mAnalyzerInformation->setFileInfo("CheckUnusedFunctions", mUnusedFunctionsCheck->analyzerInfo());

0 commit comments

Comments
 (0)