|
32 | 32 | #include "path.h" |
33 | 33 | #include "platform.h" |
34 | 34 | #include "preprocessor.h" |
| 35 | +#include "settings.h" |
35 | 36 | #include "standards.h" |
36 | 37 | #include "suppressions.h" |
37 | 38 | #include "timer.h" |
@@ -528,11 +529,13 @@ static std::string getDefinesFlags(const std::string &semicolonSeparatedString) |
528 | 529 | return flags; |
529 | 530 | } |
530 | 531 |
|
531 | | -CppCheck::CppCheck(Suppressions& supprs, |
| 532 | +CppCheck::CppCheck(const Settings& settings, |
| 533 | + Suppressions& supprs, |
532 | 534 | ErrorLogger &errorLogger, |
533 | 535 | bool useGlobalSuppressions, |
534 | 536 | ExecuteCmdFn executeCommand) |
535 | | - : mSuppressions(supprs) |
| 537 | + : mSettings(settings) |
| 538 | + , mSuppressions(supprs) |
536 | 539 | , mLogger(new CppCheckLogger(errorLogger, mSettings, mSuppressions, useGlobalSuppressions)) |
537 | 540 | , mErrorLogger(*mLogger) |
538 | 541 | , mErrorLoggerDirect(errorLogger) |
@@ -783,31 +786,33 @@ unsigned int CppCheck::check(const FileSettings &fs) |
783 | 786 | if (mSettings.checks.isEnabled(Checks::unusedFunction) && !mUnusedFunctionsCheck) |
784 | 787 | mUnusedFunctionsCheck.reset(new CheckUnusedFunctions()); |
785 | 788 |
|
786 | | - // need to pass the externally provided ErrorLogger instead of our internal wrapper |
787 | | - CppCheck temp(mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand); |
788 | | - temp.mSettings = mSettings; |
789 | | - if (!temp.mSettings.userDefines.empty()) |
790 | | - temp.mSettings.userDefines += ';'; |
| 789 | + Settings tempSettings = mSettings; // this is a copy |
| 790 | + if (!tempSettings.userDefines.empty()) |
| 791 | + tempSettings.userDefines += ';'; |
791 | 792 | if (mSettings.clang) |
792 | | - temp.mSettings.userDefines += fs.defines; |
| 793 | + tempSettings.userDefines += fs.defines; |
793 | 794 | else |
794 | | - temp.mSettings.userDefines += fs.cppcheckDefines(); |
795 | | - temp.mSettings.includePaths = fs.includePaths; |
796 | | - temp.mSettings.userUndefs.insert(fs.undefs.cbegin(), fs.undefs.cend()); |
| 795 | + tempSettings.userDefines += fs.cppcheckDefines(); |
| 796 | + tempSettings.includePaths = fs.includePaths; |
| 797 | + tempSettings.userUndefs.insert(fs.undefs.cbegin(), fs.undefs.cend()); |
797 | 798 | if (fs.standard.find("++") != std::string::npos) |
798 | | - temp.mSettings.standards.setCPP(fs.standard); |
| 799 | + tempSettings.standards.setCPP(fs.standard); |
799 | 800 | else if (!fs.standard.empty()) |
800 | | - temp.mSettings.standards.setC(fs.standard); |
| 801 | + tempSettings.standards.setC(fs.standard); |
801 | 802 | if (fs.platformType != Platform::Type::Unspecified) |
802 | | - temp.mSettings.platform.set(fs.platformType); |
| 803 | + tempSettings.platform.set(fs.platformType); |
803 | 804 | if (mSettings.clang) { |
804 | | - temp.mSettings.includePaths.insert(temp.mSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend()); |
| 805 | + tempSettings.includePaths.insert(tempSettings.includePaths.end(), fs.systemIncludePaths.cbegin(), fs.systemIncludePaths.cend()); |
| 806 | + // need to pass the externally provided ErrorLogger instead of our internal wrapper |
| 807 | + CppCheck temp(tempSettings, mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand); |
805 | 808 | // TODO: propagate back mFileInfo |
806 | 809 | const unsigned int returnValue = temp.check(fs.file); |
807 | 810 | if (mUnusedFunctionsCheck) |
808 | 811 | mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck); |
809 | 812 | return returnValue; |
810 | 813 | } |
| 814 | + // need to pass the externally provided ErrorLogger instead of our internal wrapper |
| 815 | + CppCheck temp(tempSettings, mSuppressions, mErrorLoggerDirect, mUseGlobalSuppressions, mExecuteCommand); |
811 | 816 | const unsigned int returnValue = temp.checkFile(fs.file, fs.cfg); |
812 | 817 | if (mUnusedFunctionsCheck) |
813 | 818 | mUnusedFunctionsCheck->updateFunctionData(*temp.mUnusedFunctionsCheck); |
@@ -1791,11 +1796,6 @@ void CppCheck::executeAddonsWholeProgram(const std::list<FileWithDetails> &files |
1791 | 1796 | executeAddons(ctuInfoFiles, ""); |
1792 | 1797 | } |
1793 | 1798 |
|
1794 | | -Settings &CppCheck::settings() |
1795 | | -{ |
1796 | | - return mSettings; |
1797 | | -} |
1798 | | - |
1799 | 1799 | void CppCheck::tooManyConfigsError(const std::string &file, const int numberOfConfigurations) |
1800 | 1800 | { |
1801 | 1801 | if (!mSettings.severity.isEnabled(Severity::information) && !mTooManyConfigs) |
@@ -1861,16 +1861,18 @@ void CppCheck::purgedConfigurationMessage(const std::string &file, const std::st |
1861 | 1861 |
|
1862 | 1862 | void CppCheck::getErrorMessages(ErrorLogger &errorlogger) |
1863 | 1863 | { |
1864 | | - Settings s; |
1865 | | - s.addEnabled("all"); |
| 1864 | + Settings settings; |
1866 | 1865 | Suppressions supprs; |
1867 | 1866 |
|
1868 | | - CppCheck cppcheck(supprs, errorlogger, true, nullptr); |
| 1867 | + CppCheck cppcheck(settings, supprs, errorlogger, true, nullptr); |
1869 | 1868 | cppcheck.purgedConfigurationMessage("",""); |
1870 | 1869 | cppcheck.mTooManyConfigs = true; |
1871 | 1870 | cppcheck.tooManyConfigsError("",0U); |
1872 | 1871 | // TODO: add functions to get remaining error messages |
1873 | 1872 |
|
| 1873 | + Settings s; |
| 1874 | + s.addEnabled("all"); |
| 1875 | + |
1874 | 1876 | // call all "getErrorMessages" in all registered Check classes |
1875 | 1877 | for (auto it = Check::instances().cbegin(); it != Check::instances().cend(); ++it) |
1876 | 1878 | (*it)->getErrorMessages(&errorlogger, &s); |
|
0 commit comments