Skip to content

Commit 54750e0

Browse files
committed
CppCheck: extracted hash calculation into helper
1 parent a3c6266 commit 54750e0

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lib/cppcheck.cpp

+15-12
Original file line numberDiff line numberDiff line change
@@ -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+
627641
unsigned 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
@@ -752,19 +766,8 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
752766
mAnalyzerInformation.reset(new AnalyzerInformation);
753767

754768
if (mAnalyzerInformation) {
755-
// Get toolinfo
756-
std::ostringstream toolinfo;
757-
toolinfo << CPPCHECK_VERSION_STRING;
758-
toolinfo << (mSettings.severity.isEnabled(Severity::warning) ? 'w' : ' ');
759-
toolinfo << (mSettings.severity.isEnabled(Severity::style) ? 's' : ' ');
760-
toolinfo << (mSettings.severity.isEnabled(Severity::performance) ? 'p' : ' ');
761-
toolinfo << (mSettings.severity.isEnabled(Severity::portability) ? 'p' : ' ');
762-
toolinfo << (mSettings.severity.isEnabled(Severity::information) ? 'i' : ' ');
763-
toolinfo << mSettings.userDefines;
764-
mSettings.supprs.nomsg.dump(toolinfo);
765-
766769
// Calculate hash so it can be compared with old hash / future hashes
767-
const std::size_t hash = preprocessor.calculateHash(tokens1, toolinfo.str());
770+
const std::size_t hash = calculateHash(preprocessor, tokens1, mSettings);
768771
std::list<ErrorMessage> errors;
769772
if (!mAnalyzerInformation->analyzeFile(mSettings.buildDir, file.spath(), cfgname, hash, errors)) {
770773
while (!errors.empty()) {

0 commit comments

Comments
 (0)