Skip to content

Commit

Permalink
CppCheck: calculate proper hash for markup file analyzer information
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Dec 3, 2024
1 parent 47b3e62 commit 48283a4
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,22 +683,32 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
mAnalyzerInformation.reset(new AnalyzerInformation);

if (mUnusedFunctionsCheck && (mSettings.useSingleJob() || mAnalyzerInformation)) {
std::size_t hash = 0;
// 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.
Tokenizer tokenizer(mSettings, *this);
// enforce the language since markup files are special and do not adhere to the enforced language
tokenizer.list.setLang(Standards::Language::C, true);
if (fileStream) {
tokenizer.list.createTokens(*fileStream, file.spath());
std::vector<std::string> files{file.spath()};
simplecpp::TokenList tokens(*fileStream, files);
if (mAnalyzerInformation) {
const Preprocessor preprocessor(mSettings, *this);
hash = calculateHash(preprocessor, tokens, mSettings);
}
tokenizer.list.createTokens(std::move(tokens));
}
else {
std::ifstream in(file.spath());
tokenizer.list.createTokens(in, file.spath());
std::vector<std::string> files{file.spath()};
simplecpp::TokenList tokens(file.spath(), files);
if (mAnalyzerInformation) {
const Preprocessor preprocessor(mSettings, *this);
hash = calculateHash(preprocessor, tokens, mSettings);
}
tokenizer.list.createTokens(std::move(tokens));
}
mUnusedFunctionsCheck->parseTokens(tokenizer, mSettings);

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

0 comments on commit 48283a4

Please sign in to comment.