@@ -624,6 +624,20 @@ static simplecpp::TokenList createTokenList(const std::string& filename, std::ve
624
624
return {filename, files, outputList};
625
625
}
626
626
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
+
627
641
unsigned int CppCheck::checkFile (const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream)
628
642
{
629
643
// 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
665
679
666
680
try {
667
681
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 ;
669
687
// 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.
670
688
Tokenizer tokenizer (mSettings , *this );
671
689
// enforce the language since markup files are special and do not adhere to the enforced language
672
690
tokenizer.list .setLang (Standards::Language::C, true );
673
691
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));
675
699
}
676
700
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));
679
708
}
680
709
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
+ }
682
717
}
683
718
return EXIT_SUCCESS;
684
719
}
@@ -745,19 +780,8 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
745
780
mAnalyzerInformation .reset (new AnalyzerInformation);
746
781
747
782
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
-
759
783
// 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 );
761
785
std::list<ErrorMessage> errors;
762
786
if (!mAnalyzerInformation ->analyzeFile (mSettings .buildDir , file.spath (), cfgname, hash, errors)) {
763
787
while (!errors.empty ()) {
0 commit comments