Skip to content

Commit 837c5cb

Browse files
committed
CppCheck: extracted hash calculation into helper
1 parent 732f375 commit 837c5cb

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

lib/cppcheck.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,20 @@ static simplecpp::TokenList createTokenList(const std::string& filename, std::ve
620620
return {filename, files, outputList};
621621
}
622622

623+
static std::size_t calculateHash(const Preprocessor& preprocessor, const simplecpp::TokenList& tokens, const Settings& settings)
624+
{
625+
std::ostringstream toolinfo;
626+
toolinfo << CPPCHECK_VERSION_STRING;
627+
toolinfo << (settings.severity.isEnabled(Severity::warning) ? 'w' : ' ');
628+
toolinfo << (settings.severity.isEnabled(Severity::style) ? 's' : ' ');
629+
toolinfo << (settings.severity.isEnabled(Severity::performance) ? 'p' : ' ');
630+
toolinfo << (settings.severity.isEnabled(Severity::portability) ? 'p' : ' ');
631+
toolinfo << (settings.severity.isEnabled(Severity::information) ? 'i' : ' ');
632+
toolinfo << settings.userDefines;
633+
settings.supprs.nomsg.dump(toolinfo);
634+
return preprocessor.calculateHash(tokens, toolinfo.str());
635+
}
636+
623637
unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string &cfgname, std::istream* fileStream)
624638
{
625639
// TODO: move to constructor when CppCheck no longer owns the settings
@@ -740,19 +754,8 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
740754
preprocessor.removeComments(tokens1);
741755

742756
if (!mSettings.buildDir.empty()) {
743-
// Get toolinfo
744-
std::ostringstream toolinfo;
745-
toolinfo << CPPCHECK_VERSION_STRING;
746-
toolinfo << (mSettings.severity.isEnabled(Severity::warning) ? 'w' : ' ');
747-
toolinfo << (mSettings.severity.isEnabled(Severity::style) ? 's' : ' ');
748-
toolinfo << (mSettings.severity.isEnabled(Severity::performance) ? 'p' : ' ');
749-
toolinfo << (mSettings.severity.isEnabled(Severity::portability) ? 'p' : ' ');
750-
toolinfo << (mSettings.severity.isEnabled(Severity::information) ? 'i' : ' ');
751-
toolinfo << mSettings.userDefines;
752-
mSettings.supprs.nomsg.dump(toolinfo);
753-
754757
// Calculate hash so it can be compared with old hash / future hashes
755-
const std::size_t hash = preprocessor.calculateHash(tokens1, toolinfo.str());
758+
const std::size_t hash = calculateHash(preprocessor, tokens1, mSettings);
756759
std::list<ErrorMessage> errors;
757760
if (!mAnalyzerInformation.analyzeFile(mSettings.buildDir, file.spath(), cfgname, hash, errors)) {
758761
while (!errors.empty()) {

0 commit comments

Comments
 (0)