@@ -624,6 +624,20 @@ static simplecpp::TokenList createTokenList(const std::string& filename, std::ve
624624 return {filename, files, outputList};
625625}
626626
627+ static std::size_t calculateHash (const Preprocessor& preprocessor, const simplecpp::TokenList& tokens, const Settings& settings)
628+ {
629+ std::ostringstream toolinfo;
630+ toolinfo << CPPCHECK_VERSION_STRING;
631+ toolinfo << (settings.severity .isEnabled (Severity::warning) ? ' w' : ' ' );
632+ toolinfo << (settings.severity .isEnabled (Severity::style) ? ' s' : ' ' );
633+ toolinfo << (settings.severity .isEnabled (Severity::performance) ? ' p' : ' ' );
634+ toolinfo << (settings.severity .isEnabled (Severity::portability) ? ' p' : ' ' );
635+ toolinfo << (settings.severity .isEnabled (Severity::information) ? ' i' : ' ' );
636+ toolinfo << settings.userDefines ;
637+ settings.supprs .nomsg .dump (toolinfo);
638+ return preprocessor.calculateHash (tokens, toolinfo.str ());
639+ }
640+
627641unsigned int CppCheck::checkFile (const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream)
628642{
629643 // TODO: move to constructor when CppCheck no longer owns the settings
@@ -665,20 +679,41 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
665679
666680 try {
667681 if (mSettings .library .markupFile (file.spath ())) {
668- if (mUnusedFunctionsCheck && (mSettings .useSingleJob () || !mSettings .buildDir .empty ())) {
682+ if (!mSettings .buildDir .empty ())
683+ mAnalyzerInformation .reset (new AnalyzerInformation);
684+
685+ if (mUnusedFunctionsCheck && (mSettings .useSingleJob () || mAnalyzerInformation )) {
686+ std::size_t hash = 0 ;
669687 // 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.
670688 Tokenizer tokenizer (mSettings , *this );
671689 // enforce the language since markup files are special and do not adhere to the enforced language
672690 tokenizer.list .setLang (Standards::Language::C, true );
673691 if (fileStream) {
674- 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));
675699 }
676700 else {
677- std::ifstream in (file.spath ());
678- 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));
679708 }
680709 mUnusedFunctionsCheck ->parseTokens (tokenizer, mSettings );
681- // TODO: set analyzer information
710+
711+ if (mAnalyzerInformation ) {
712+ std::list<ErrorMessage> errors;
713+ mAnalyzerInformation ->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors);
714+ mAnalyzerInformation ->setFileInfo (" CheckUnusedFunctions" , mUnusedFunctionsCheck ->analyzerInfo ());
715+ mAnalyzerInformation ->close ();
716+ }
682717 }
683718 return EXIT_SUCCESS;
684719 }
@@ -745,19 +780,8 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
745780 mAnalyzerInformation .reset (new AnalyzerInformation);
746781
747782 if (mAnalyzerInformation ) {
748- // Get toolinfo
749- std::ostringstream toolinfo;
750- toolinfo << CPPCHECK_VERSION_STRING;
751- toolinfo << (mSettings .severity .isEnabled (Severity::warning) ? ' w' : ' ' );
752- toolinfo << (mSettings .severity .isEnabled (Severity::style) ? ' s' : ' ' );
753- toolinfo << (mSettings .severity .isEnabled (Severity::performance) ? ' p' : ' ' );
754- toolinfo << (mSettings .severity .isEnabled (Severity::portability) ? ' p' : ' ' );
755- toolinfo << (mSettings .severity .isEnabled (Severity::information) ? ' i' : ' ' );
756- toolinfo << mSettings .userDefines ;
757- mSettings .supprs .nomsg .dump (toolinfo);
758-
759783 // Calculate hash so it can be compared with old hash / future hashes
760- const std::size_t hash = preprocessor. calculateHash (tokens1, toolinfo. str () );
784+ const std::size_t hash = calculateHash (preprocessor, tokens1, mSettings );
761785 std::list<ErrorMessage> errors;
762786 if (!mAnalyzerInformation ->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors)) {
763787 while (!errors.empty ()) {
0 commit comments