diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 74c1c8d1c38d..9e0b1ea80c76 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -680,21 +680,27 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string try { if (mSettings.library.markupFile(file.spath())) { if (mUnusedFunctionsCheck && (mSettings.useSingleJob() || !mSettings.buildDir.empty())) { + std::size_t hash; // 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 files{file.spath()}; + simplecpp::TokenList tokens(*fileStream, files); + 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 files{file.spath()}; + simplecpp::TokenList tokens(file.spath(), files); + const Preprocessor preprocessor(mSettings, *this); + hash = calculateHash(preprocessor, tokens, mSettings); + tokenizer.list.createTokens(std::move(tokens)); } mUnusedFunctionsCheck->parseTokens(tokenizer, mSettings); - // 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 errors; mAnalyzerInformation.analyzeFile(mSettings.buildDir, file.spath(), cfgname, hash, errors); mAnalyzerInformation.setFileInfo("CheckUnusedFunctions", mUnusedFunctionsCheck->analyzerInfo());