made `CmdLineParser::mSettings` a reference (#4855)
This commit is contained in:
parent
0719a57ca8
commit
d17e804235
|
@ -113,7 +113,7 @@ static bool addPathsToSet(const std::string& fileName, std::set<std::string>& se
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CmdLineParser::CmdLineParser(Settings *settings)
|
CmdLineParser::CmdLineParser(Settings &settings)
|
||||||
: mSettings(settings)
|
: mSettings(settings)
|
||||||
, mShowHelp(false)
|
, mShowHelp(false)
|
||||||
, mShowVersion(false)
|
, mShowVersion(false)
|
||||||
|
@ -146,13 +146,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
bool def = false;
|
bool def = false;
|
||||||
bool maxconfigs = false;
|
bool maxconfigs = false;
|
||||||
|
|
||||||
mSettings->exename = argv[0];
|
mSettings.exename = argv[0];
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
// Executing cppcheck in PATH. argv[0] does not contain the path.
|
// Executing cppcheck in PATH. argv[0] does not contain the path.
|
||||||
if (mSettings->exename.find_first_of("/\\") == std::string::npos) {
|
if (mSettings.exename.find_first_of("/\\") == std::string::npos) {
|
||||||
char buf[PATH_MAX] = {0};
|
char buf[PATH_MAX] = {0};
|
||||||
if (FileLister::fileExists("/proc/self/exe") && readlink("/proc/self/exe", buf, sizeof(buf)-1) > 0)
|
if (FileLister::fileExists("/proc/self/exe") && readlink("/proc/self/exe", buf, sizeof(buf)-1) > 0)
|
||||||
mSettings->exename = buf;
|
mSettings.exename = buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -181,17 +181,17 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
if (define.find('=') == std::string::npos)
|
if (define.find('=') == std::string::npos)
|
||||||
define += "=1";
|
define += "=1";
|
||||||
|
|
||||||
if (!mSettings->userDefines.empty())
|
if (!mSettings.userDefines.empty())
|
||||||
mSettings->userDefines += ";";
|
mSettings.userDefines += ";";
|
||||||
mSettings->userDefines += define;
|
mSettings.userDefines += define;
|
||||||
|
|
||||||
def = true;
|
def = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -E
|
// -E
|
||||||
else if (std::strcmp(argv[i], "-E") == 0) {
|
else if (std::strcmp(argv[i], "-E") == 0) {
|
||||||
mSettings->preprocessOnly = true;
|
mSettings.preprocessOnly = true;
|
||||||
mSettings->quiet = true;
|
mSettings.quiet = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Include paths
|
// Include paths
|
||||||
|
@ -219,7 +219,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
if (!endsWith(path,'/'))
|
if (!endsWith(path,'/'))
|
||||||
path += '/';
|
path += '/';
|
||||||
|
|
||||||
mSettings->includePaths.emplace_back(std::move(path));
|
mSettings.includePaths.emplace_back(std::move(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// User undef
|
// User undef
|
||||||
|
@ -241,75 +241,75 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
undef = 2 + argv[i];
|
undef = 2 + argv[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
mSettings->userUndefs.insert(std::move(undef));
|
mSettings.userUndefs.insert(std::move(undef));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--addon=", 8) == 0)
|
else if (std::strncmp(argv[i], "--addon=", 8) == 0)
|
||||||
mSettings->addons.emplace(argv[i]+8);
|
mSettings.addons.emplace(argv[i]+8);
|
||||||
|
|
||||||
else if (std::strncmp(argv[i],"--addon-python=", 15) == 0)
|
else if (std::strncmp(argv[i],"--addon-python=", 15) == 0)
|
||||||
mSettings->addonPython.assign(argv[i]+15);
|
mSettings.addonPython.assign(argv[i]+15);
|
||||||
|
|
||||||
// Check configuration
|
// Check configuration
|
||||||
else if (std::strcmp(argv[i], "--check-config") == 0)
|
else if (std::strcmp(argv[i], "--check-config") == 0)
|
||||||
mSettings->checkConfiguration = true;
|
mSettings.checkConfiguration = true;
|
||||||
|
|
||||||
// Check library definitions
|
// Check library definitions
|
||||||
else if (std::strcmp(argv[i], "--check-library") == 0) {
|
else if (std::strcmp(argv[i], "--check-library") == 0) {
|
||||||
mSettings->checkLibrary = true;
|
mSettings.checkLibrary = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--checks-max-time=", 18) == 0) {
|
else if (std::strncmp(argv[i], "--checks-max-time=", 18) == 0) {
|
||||||
mSettings->checksMaxTime = std::atoi(argv[i] + 18);
|
mSettings.checksMaxTime = std::atoi(argv[i] + 18);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strcmp(argv[i], "--clang") == 0) {
|
else if (std::strcmp(argv[i], "--clang") == 0) {
|
||||||
mSettings->clang = true;
|
mSettings.clang = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--clang=", 8) == 0) {
|
else if (std::strncmp(argv[i], "--clang=", 8) == 0) {
|
||||||
mSettings->clang = true;
|
mSettings.clang = true;
|
||||||
mSettings->clangExecutable = argv[i] + 8;
|
mSettings.clangExecutable = argv[i] + 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) {
|
else if (std::strncmp(argv[i], "--config-exclude=",17) ==0) {
|
||||||
mSettings->configExcludePaths.insert(Path::fromNativeSeparators(argv[i] + 17));
|
mSettings.configExcludePaths.insert(Path::fromNativeSeparators(argv[i] + 17));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--config-excludes-file=", 23) == 0) {
|
else if (std::strncmp(argv[i], "--config-excludes-file=", 23) == 0) {
|
||||||
// open this file and read every input file (1 file name per line)
|
// open this file and read every input file (1 file name per line)
|
||||||
const std::string cfgExcludesFile(23 + argv[i]);
|
const std::string cfgExcludesFile(23 + argv[i]);
|
||||||
if (!addPathsToSet(cfgExcludesFile, mSettings->configExcludePaths)) {
|
if (!addPathsToSet(cfgExcludesFile, mSettings.configExcludePaths)) {
|
||||||
printError("unable to open config excludes file at '" + cfgExcludesFile + "'");
|
printError("unable to open config excludes file at '" + cfgExcludesFile + "'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0) {
|
else if (std::strncmp(argv[i], "--cppcheck-build-dir=", 21) == 0) {
|
||||||
mSettings->buildDir = Path::fromNativeSeparators(argv[i] + 21);
|
mSettings.buildDir = Path::fromNativeSeparators(argv[i] + 21);
|
||||||
if (endsWith(mSettings->buildDir, '/'))
|
if (endsWith(mSettings.buildDir, '/'))
|
||||||
mSettings->buildDir.pop_back();
|
mSettings.buildDir.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show --debug output after the first simplifications
|
// Show --debug output after the first simplifications
|
||||||
else if (std::strcmp(argv[i], "--debug") == 0 ||
|
else if (std::strcmp(argv[i], "--debug") == 0 ||
|
||||||
std::strcmp(argv[i], "--debug-normal") == 0)
|
std::strcmp(argv[i], "--debug-normal") == 0)
|
||||||
mSettings->debugnormal = true;
|
mSettings.debugnormal = true;
|
||||||
|
|
||||||
// Flag used for various purposes during debugging
|
// Flag used for various purposes during debugging
|
||||||
else if (std::strcmp(argv[i], "--debug-simplified") == 0)
|
else if (std::strcmp(argv[i], "--debug-simplified") == 0)
|
||||||
mSettings->debugSimplified = true;
|
mSettings.debugSimplified = true;
|
||||||
|
|
||||||
// Show template information
|
// Show template information
|
||||||
else if (std::strcmp(argv[i], "--debug-template") == 0)
|
else if (std::strcmp(argv[i], "--debug-template") == 0)
|
||||||
mSettings->debugtemplate = true;
|
mSettings.debugtemplate = true;
|
||||||
|
|
||||||
// Show debug warnings
|
// Show debug warnings
|
||||||
else if (std::strcmp(argv[i], "--debug-warnings") == 0)
|
else if (std::strcmp(argv[i], "--debug-warnings") == 0)
|
||||||
mSettings->debugwarnings = true;
|
mSettings.debugwarnings = true;
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--disable=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--disable=", 10) == 0) {
|
||||||
const std::string errmsg = mSettings->removeEnabled(argv[i] + 10);
|
const std::string errmsg = mSettings.removeEnabled(argv[i] + 10);
|
||||||
if (!errmsg.empty()) {
|
if (!errmsg.empty()) {
|
||||||
printError(errmsg);
|
printError(errmsg);
|
||||||
return false;
|
return false;
|
||||||
|
@ -335,27 +335,27 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// dump cppcheck data
|
// dump cppcheck data
|
||||||
else if (std::strcmp(argv[i], "--dump") == 0)
|
else if (std::strcmp(argv[i], "--dump") == 0)
|
||||||
mSettings->dump = true;
|
mSettings.dump = true;
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
|
else if (std::strncmp(argv[i], "--enable=", 9) == 0) {
|
||||||
const std::string enable_arg = argv[i] + 9;
|
const std::string enable_arg = argv[i] + 9;
|
||||||
const std::string errmsg = mSettings->addEnabled(enable_arg);
|
const std::string errmsg = mSettings.addEnabled(enable_arg);
|
||||||
if (!errmsg.empty()) {
|
if (!errmsg.empty()) {
|
||||||
printError(errmsg);
|
printError(errmsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// when "style" is enabled, also enable "warning", "performance" and "portability"
|
// when "style" is enabled, also enable "warning", "performance" and "portability"
|
||||||
if (enable_arg.find("style") != std::string::npos) {
|
if (enable_arg.find("style") != std::string::npos) {
|
||||||
mSettings->addEnabled("warning");
|
mSettings.addEnabled("warning");
|
||||||
mSettings->addEnabled("performance");
|
mSettings.addEnabled("performance");
|
||||||
mSettings->addEnabled("portability");
|
mSettings.addEnabled("portability");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// print all possible error messages..
|
// print all possible error messages..
|
||||||
else if (std::strcmp(argv[i], "--errorlist") == 0) {
|
else if (std::strcmp(argv[i], "--errorlist") == 0) {
|
||||||
mShowErrorMessages = true;
|
mShowErrorMessages = true;
|
||||||
mSettings->xml = true;
|
mSettings.xml = true;
|
||||||
mExitAfterPrint = true;
|
mExitAfterPrint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,7 +363,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) {
|
else if (std::strncmp(argv[i], "--error-exitcode=", 17) == 0) {
|
||||||
const std::string temp = argv[i]+17;
|
const std::string temp = argv[i]+17;
|
||||||
std::istringstream iss(temp);
|
std::istringstream iss(temp);
|
||||||
if (!(iss >> mSettings->exitCode)) {
|
if (!(iss >> mSettings.exitCode)) {
|
||||||
printError("argument must be an integer. Try something like '--error-exitcode=1'.");
|
printError("argument must be an integer. Try something like '--error-exitcode=1'.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// Exception handling inside cppcheck client
|
// Exception handling inside cppcheck client
|
||||||
else if (std::strcmp(argv[i], "--exception-handling") == 0) {
|
else if (std::strcmp(argv[i], "--exception-handling") == 0) {
|
||||||
mSettings->exceptionHandling = true;
|
mSettings.exceptionHandling = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exception handling inside cppcheck client
|
// Exception handling inside cppcheck client
|
||||||
|
@ -381,7 +381,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
printError("invalid '--exception-handling' argument");
|
printError("invalid '--exception-handling' argument");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mSettings->exceptionHandling = true;
|
mSettings.exceptionHandling = true;
|
||||||
CppCheckExecutor::setExceptionOutput((exceptionOutfilename == "stderr") ? stderr : stdout);
|
CppCheckExecutor::setExceptionOutput((exceptionOutfilename == "stderr") ? stderr : stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
printError("couldn't open the file: \"" + filename + "\".");
|
printError("couldn't open the file: \"" + filename + "\".");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const std::string errmsg(mSettings->nofail.parseFile(f));
|
const std::string errmsg(mSettings.nofail.parseFile(f));
|
||||||
if (!errmsg.empty()) {
|
if (!errmsg.empty()) {
|
||||||
printError(errmsg);
|
printError(errmsg);
|
||||||
return false;
|
return false;
|
||||||
|
@ -404,7 +404,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// use a file filter
|
// use a file filter
|
||||||
else if (std::strncmp(argv[i], "--file-filter=", 14) == 0)
|
else if (std::strncmp(argv[i], "--file-filter=", 14) == 0)
|
||||||
mSettings->fileFilters.emplace_back(argv[i] + 14);
|
mSettings.fileFilters.emplace_back(argv[i] + 14);
|
||||||
|
|
||||||
// file list specified
|
// file list specified
|
||||||
else if (std::strncmp(argv[i], "--file-list=", 12) == 0) {
|
else if (std::strncmp(argv[i], "--file-list=", 12) == 0) {
|
||||||
|
@ -418,7 +418,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// Force checking of files that have "too many" configurations
|
// Force checking of files that have "too many" configurations
|
||||||
else if (std::strcmp(argv[i], "-f") == 0 || std::strcmp(argv[i], "--force") == 0)
|
else if (std::strcmp(argv[i], "-f") == 0 || std::strcmp(argv[i], "--force") == 0)
|
||||||
mSettings->force = true;
|
mSettings.force = true;
|
||||||
|
|
||||||
// Print help
|
// Print help
|
||||||
else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) {
|
else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) {
|
||||||
|
@ -462,13 +462,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--include=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--include=", 10) == 0) {
|
||||||
mSettings->userIncludes.emplace_back(Path::fromNativeSeparators(argv[i] + 10));
|
mSettings.userIncludes.emplace_back(Path::fromNativeSeparators(argv[i] + 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
|
else if (std::strncmp(argv[i], "--includes-file=", 16) == 0) {
|
||||||
// open this file and read every input file (1 file name per line)
|
// open this file and read every input file (1 file name per line)
|
||||||
const std::string includesFile(16 + argv[i]);
|
const std::string includesFile(16 + argv[i]);
|
||||||
if (!addIncludePathsToList(includesFile, mSettings->includePaths)) {
|
if (!addIncludePathsToList(includesFile, mSettings.includePaths)) {
|
||||||
printError("unable to open includes file at '" + includesFile + "'");
|
printError("unable to open includes file at '" + includesFile + "'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -476,11 +476,11 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// Inconclusive checking
|
// Inconclusive checking
|
||||||
else if (std::strcmp(argv[i], "--inconclusive") == 0)
|
else if (std::strcmp(argv[i], "--inconclusive") == 0)
|
||||||
mSettings->certainty.enable(Certainty::inconclusive);
|
mSettings.certainty.enable(Certainty::inconclusive);
|
||||||
|
|
||||||
// Enables inline suppressions.
|
// Enables inline suppressions.
|
||||||
else if (std::strcmp(argv[i], "--inline-suppr") == 0)
|
else if (std::strcmp(argv[i], "--inline-suppr") == 0)
|
||||||
mSettings->inlineSuppressions = true;
|
mSettings.inlineSuppressions = true;
|
||||||
|
|
||||||
// Checking threads
|
// Checking threads
|
||||||
else if (std::strncmp(argv[i], "-j", 2) == 0) {
|
else if (std::strncmp(argv[i], "-j", 2) == 0) {
|
||||||
|
@ -502,12 +502,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
numberString = argv[i]+2;
|
numberString = argv[i]+2;
|
||||||
|
|
||||||
std::istringstream iss(numberString);
|
std::istringstream iss(numberString);
|
||||||
if (!(iss >> mSettings->jobs)) {
|
if (!(iss >> mSettings.jobs)) {
|
||||||
printError("argument to '-j' is not a number.");
|
printError("argument to '-j' is not a number.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSettings->jobs > 10000) {
|
if (mSettings.jobs > 10000) {
|
||||||
// This limit is here just to catch typos. If someone has
|
// This limit is here just to catch typos. If someone has
|
||||||
// need for more jobs, this value should be increased.
|
// need for more jobs, this value should be increased.
|
||||||
printError("argument for '-j' is allowed to be 10000 at max.");
|
printError("argument for '-j' is allowed to be 10000 at max.");
|
||||||
|
@ -535,7 +535,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
numberString = argv[i]+2;
|
numberString = argv[i]+2;
|
||||||
|
|
||||||
std::istringstream iss(numberString);
|
std::istringstream iss(numberString);
|
||||||
if (!(iss >> mSettings->loadAverage)) {
|
if (!(iss >> mSettings.loadAverage)) {
|
||||||
printError("argument to '-l' is not a number.");
|
printError("argument to '-l' is not a number.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -557,9 +557,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str == "c")
|
if (str == "c")
|
||||||
mSettings->enforcedLang = Settings::Language::C;
|
mSettings.enforcedLang = Settings::Language::C;
|
||||||
else if (str == "c++")
|
else if (str == "c++")
|
||||||
mSettings->enforcedLang = Settings::Language::CPP;
|
mSettings.enforcedLang = Settings::Language::CPP;
|
||||||
else {
|
else {
|
||||||
printError("unknown language '" + str + "' enforced.");
|
printError("unknown language '" + str + "' enforced.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -568,20 +568,20 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// --library
|
// --library
|
||||||
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--library=", 10) == 0) {
|
||||||
mSettings->libraries.emplace_back(argv[i] + 10);
|
mSettings.libraries.emplace_back(argv[i] + 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set maximum number of #ifdef configurations to check
|
// Set maximum number of #ifdef configurations to check
|
||||||
else if (std::strncmp(argv[i], "--max-configs=", 14) == 0) {
|
else if (std::strncmp(argv[i], "--max-configs=", 14) == 0) {
|
||||||
mSettings->force = false;
|
mSettings.force = false;
|
||||||
|
|
||||||
std::istringstream iss(14+argv[i]);
|
std::istringstream iss(14+argv[i]);
|
||||||
if (!(iss >> mSettings->maxConfigs)) {
|
if (!(iss >> mSettings.maxConfigs)) {
|
||||||
printError("argument to '--max-configs=' is not a number.");
|
printError("argument to '--max-configs=' is not a number.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSettings->maxConfigs < 1) {
|
if (mSettings.maxConfigs < 1) {
|
||||||
printError("argument to '--max-configs=' must be greater than 0.");
|
printError("argument to '--max-configs=' must be greater than 0.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -591,16 +591,16 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// max ctu depth
|
// max ctu depth
|
||||||
else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0)
|
else if (std::strncmp(argv[i], "--max-ctu-depth=", 16) == 0)
|
||||||
mSettings->maxCtuDepth = std::atoi(argv[i] + 16);
|
mSettings.maxCtuDepth = std::atoi(argv[i] + 16);
|
||||||
|
|
||||||
// Write results in file
|
// Write results in file
|
||||||
else if (std::strncmp(argv[i], "--output-file=", 14) == 0)
|
else if (std::strncmp(argv[i], "--output-file=", 14) == 0)
|
||||||
mSettings->outputFile = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 14));
|
mSettings.outputFile = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 14));
|
||||||
|
|
||||||
// Experimental: limit execution time for extended valueflow analysis. basic valueflow analysis
|
// Experimental: limit execution time for extended valueflow analysis. basic valueflow analysis
|
||||||
// is always executed.
|
// is always executed.
|
||||||
else if (std::strncmp(argv[i], "--performance-valueflow-max-time=", 33) == 0)
|
else if (std::strncmp(argv[i], "--performance-valueflow-max-time=", 33) == 0)
|
||||||
mSettings->performanceValueFlowMaxTime = std::atoi(argv[i] + 33);
|
mSettings.performanceValueFlowMaxTime = std::atoi(argv[i] + 33);
|
||||||
|
|
||||||
// Specify platform
|
// Specify platform
|
||||||
else if (std::strncmp(argv[i], "--platform=", 11) == 0) {
|
else if (std::strncmp(argv[i], "--platform=", 11) == 0) {
|
||||||
|
@ -608,7 +608,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
std::string errstr;
|
std::string errstr;
|
||||||
const std::vector<std::string> paths = {argv[0]};
|
const std::vector<std::string> paths = {argv[0]};
|
||||||
if (!mSettings->platform.set(platform, errstr, paths)) {
|
if (!mSettings.platform.set(platform, errstr, paths)) {
|
||||||
printError(errstr);
|
printError(errstr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -621,20 +621,20 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
// these are loaded via external files and thus have Settings::PlatformFile set instead.
|
// these are loaded via external files and thus have Settings::PlatformFile set instead.
|
||||||
// override the type so they behave like the regular platforms.
|
// override the type so they behave like the regular platforms.
|
||||||
if (platform == "unix32-unsigned")
|
if (platform == "unix32-unsigned")
|
||||||
mSettings->platform.type = cppcheck::Platform::Type::Unix32;
|
mSettings.platform.type = cppcheck::Platform::Type::Unix32;
|
||||||
else if (platform == "unix64-unsigned")
|
else if (platform == "unix64-unsigned")
|
||||||
mSettings->platform.type = cppcheck::Platform::Type::Unix64;
|
mSettings.platform.type = cppcheck::Platform::Type::Unix64;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write results in results.plist
|
// Write results in results.plist
|
||||||
else if (std::strncmp(argv[i], "--plist-output=", 15) == 0) {
|
else if (std::strncmp(argv[i], "--plist-output=", 15) == 0) {
|
||||||
mSettings->plistOutput = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 15));
|
mSettings.plistOutput = Path::simplifyPath(Path::fromNativeSeparators(argv[i] + 15));
|
||||||
if (mSettings->plistOutput.empty())
|
if (mSettings.plistOutput.empty())
|
||||||
mSettings->plistOutput = "./";
|
mSettings.plistOutput = "./";
|
||||||
else if (!endsWith(mSettings->plistOutput,'/'))
|
else if (!endsWith(mSettings.plistOutput,'/'))
|
||||||
mSettings->plistOutput += '/';
|
mSettings.plistOutput += '/';
|
||||||
|
|
||||||
const std::string plistOutput = Path::toNativeSeparators(mSettings->plistOutput);
|
const std::string plistOutput = Path::toNativeSeparators(mSettings.plistOutput);
|
||||||
if (!FileLister::isDirectory(plistOutput)) {
|
if (!FileLister::isDirectory(plistOutput)) {
|
||||||
std::string message("plist folder does not exist: \"");
|
std::string message("plist folder does not exist: \"");
|
||||||
message += plistOutput;
|
message += plistOutput;
|
||||||
|
@ -646,29 +646,29 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// Special Cppcheck Premium options
|
// Special Cppcheck Premium options
|
||||||
else if (std::strncmp(argv[i], "--premium=", 10) == 0 && isCppcheckPremium()) {
|
else if (std::strncmp(argv[i], "--premium=", 10) == 0 && isCppcheckPremium()) {
|
||||||
if (!mSettings->premiumArgs.empty())
|
if (!mSettings.premiumArgs.empty())
|
||||||
mSettings->premiumArgs += " ";
|
mSettings.premiumArgs += " ";
|
||||||
const std::string p(argv[i] + 10);
|
const std::string p(argv[i] + 10);
|
||||||
mSettings->premiumArgs += "--" + p;
|
mSettings.premiumArgs += "--" + p;
|
||||||
if (p == "misra-c-2012")
|
if (p == "misra-c-2012")
|
||||||
mSettings->addons.emplace("misra");
|
mSettings.addons.emplace("misra");
|
||||||
}
|
}
|
||||||
|
|
||||||
// --project
|
// --project
|
||||||
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
|
else if (std::strncmp(argv[i], "--project=", 10) == 0) {
|
||||||
mSettings->checkAllConfigurations = false; // Can be overridden with --max-configs or --force
|
mSettings.checkAllConfigurations = false; // Can be overridden with --max-configs or --force
|
||||||
std::string projectFile = argv[i]+10;
|
std::string projectFile = argv[i]+10;
|
||||||
ImportProject::Type projType = mSettings->project.import(projectFile, mSettings);
|
ImportProject::Type projType = mSettings.project.import(projectFile, &mSettings);
|
||||||
mSettings->project.projectType = projType;
|
mSettings.project.projectType = projType;
|
||||||
if (projType == ImportProject::Type::CPPCHECK_GUI) {
|
if (projType == ImportProject::Type::CPPCHECK_GUI) {
|
||||||
mPathNames = mSettings->project.guiProject.pathNames;
|
mPathNames = mSettings.project.guiProject.pathNames;
|
||||||
for (const std::string &lib : mSettings->project.guiProject.libraries)
|
for (const std::string &lib : mSettings.project.guiProject.libraries)
|
||||||
mSettings->libraries.emplace_back(lib);
|
mSettings.libraries.emplace_back(lib);
|
||||||
|
|
||||||
const auto& excludedPaths = mSettings->project.guiProject.excludedPaths;
|
const auto& excludedPaths = mSettings.project.guiProject.excludedPaths;
|
||||||
std::copy(excludedPaths.cbegin(), excludedPaths.cend(), std::back_inserter(mIgnoredPaths));
|
std::copy(excludedPaths.cbegin(), excludedPaths.cend(), std::back_inserter(mIgnoredPaths));
|
||||||
|
|
||||||
std::string platform(mSettings->project.guiProject.platform);
|
std::string platform(mSettings.project.guiProject.platform);
|
||||||
|
|
||||||
// keep existing platform from command-line intact
|
// keep existing platform from command-line intact
|
||||||
if (!platform.empty()) {
|
if (!platform.empty()) {
|
||||||
|
@ -679,21 +679,21 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
std::string errstr;
|
std::string errstr;
|
||||||
const std::vector<std::string> paths = {projectFile, argv[0]};
|
const std::vector<std::string> paths = {projectFile, argv[0]};
|
||||||
if (!mSettings->platform.set(platform, errstr, paths)) {
|
if (!mSettings.platform.set(platform, errstr, paths)) {
|
||||||
printError(errstr);
|
printError(errstr);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mSettings->project.guiProject.projectFile.empty()) {
|
if (!mSettings.project.guiProject.projectFile.empty()) {
|
||||||
projectFile = mSettings->project.guiProject.projectFile;
|
projectFile = mSettings.project.guiProject.projectFile;
|
||||||
projType = mSettings->project.import(mSettings->project.guiProject.projectFile, mSettings);
|
projType = mSettings.project.import(mSettings.project.guiProject.projectFile, &mSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
|
if (projType == ImportProject::Type::VS_SLN || projType == ImportProject::Type::VS_VCXPROJ) {
|
||||||
if (mSettings->project.guiProject.analyzeAllVsConfigs == "false")
|
if (mSettings.project.guiProject.analyzeAllVsConfigs == "false")
|
||||||
mSettings->project.selectOneVsConfig(mSettings->platform.type);
|
mSettings.project.selectOneVsConfig(mSettings.platform.type);
|
||||||
if (!CppCheckExecutor::tryLoadLibrary(mSettings->library, argv[0], "windows.cfg")) {
|
if (!CppCheckExecutor::tryLoadLibrary(mSettings.library, argv[0], "windows.cfg")) {
|
||||||
// This shouldn't happen normally.
|
// This shouldn't happen normally.
|
||||||
printError("failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
printError("failed to load 'windows.cfg'. Your Cppcheck installation is broken. Please re-install.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -716,28 +716,28 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
// --project-configuration
|
// --project-configuration
|
||||||
else if (std::strncmp(argv[i], "--project-configuration=", 24) == 0) {
|
else if (std::strncmp(argv[i], "--project-configuration=", 24) == 0) {
|
||||||
mVSConfig = argv[i] + 24;
|
mVSConfig = argv[i] + 24;
|
||||||
if (!mVSConfig.empty() && (mSettings->project.projectType == ImportProject::Type::VS_SLN || mSettings->project.projectType == ImportProject::Type::VS_VCXPROJ))
|
if (!mVSConfig.empty() && (mSettings.project.projectType == ImportProject::Type::VS_SLN || mSettings.project.projectType == ImportProject::Type::VS_VCXPROJ))
|
||||||
mSettings->project.ignoreOtherConfigs(mVSConfig);
|
mSettings.project.ignoreOtherConfigs(mVSConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only print something when there are errors
|
// Only print something when there are errors
|
||||||
else if (std::strcmp(argv[i], "-q") == 0 || std::strcmp(argv[i], "--quiet") == 0)
|
else if (std::strcmp(argv[i], "-q") == 0 || std::strcmp(argv[i], "--quiet") == 0)
|
||||||
mSettings->quiet = true;
|
mSettings.quiet = true;
|
||||||
|
|
||||||
// Output relative paths
|
// Output relative paths
|
||||||
else if (std::strcmp(argv[i], "-rp") == 0 || std::strcmp(argv[i], "--relative-paths") == 0)
|
else if (std::strcmp(argv[i], "-rp") == 0 || std::strcmp(argv[i], "--relative-paths") == 0)
|
||||||
mSettings->relativePaths = true;
|
mSettings.relativePaths = true;
|
||||||
else if (std::strncmp(argv[i], "-rp=", 4) == 0 || std::strncmp(argv[i], "--relative-paths=", 17) == 0) {
|
else if (std::strncmp(argv[i], "-rp=", 4) == 0 || std::strncmp(argv[i], "--relative-paths=", 17) == 0) {
|
||||||
mSettings->relativePaths = true;
|
mSettings.relativePaths = true;
|
||||||
if (argv[i][argv[i][3]=='='?4:17] != 0) {
|
if (argv[i][argv[i][3]=='='?4:17] != 0) {
|
||||||
std::string paths = argv[i]+(argv[i][3]=='='?4:17);
|
std::string paths = argv[i]+(argv[i][3]=='='?4:17);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
const std::string::size_type pos = paths.find(';');
|
const std::string::size_type pos = paths.find(';');
|
||||||
if (pos == std::string::npos) {
|
if (pos == std::string::npos) {
|
||||||
mSettings->basePaths.emplace_back(Path::fromNativeSeparators(paths));
|
mSettings.basePaths.emplace_back(Path::fromNativeSeparators(paths));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mSettings->basePaths.emplace_back(Path::fromNativeSeparators(paths.substr(0, pos)));
|
mSettings.basePaths.emplace_back(Path::fromNativeSeparators(paths.substr(0, pos)));
|
||||||
paths.erase(0, pos + 1);
|
paths.erase(0, pos + 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -748,7 +748,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
// Report progress
|
// Report progress
|
||||||
else if (std::strcmp(argv[i], "--report-progress") == 0) {
|
else if (std::strcmp(argv[i], "--report-progress") == 0) {
|
||||||
mSettings->reportProgress = true;
|
mSettings.reportProgress = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_RULES
|
#ifdef HAVE_RULES
|
||||||
|
@ -756,7 +756,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
|
else if (std::strncmp(argv[i], "--rule=", 7) == 0) {
|
||||||
Settings::Rule rule;
|
Settings::Rule rule;
|
||||||
rule.pattern = 7 + argv[i];
|
rule.pattern = 7 + argv[i];
|
||||||
mSettings->rules.emplace_back(std::move(rule));
|
mSettings.rules.emplace_back(std::move(rule));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rule file
|
// Rule file
|
||||||
|
@ -794,7 +794,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rule.pattern.empty())
|
if (!rule.pattern.empty())
|
||||||
mSettings->rules.emplace_back(std::move(rule));
|
mSettings.rules.emplace_back(std::move(rule));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printError("unable to load rule-file: " + std::string(12+argv[i]));
|
printError("unable to load rule-file: " + std::string(12+argv[i]));
|
||||||
|
@ -807,13 +807,13 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
|
else if (std::strncmp(argv[i], "--showtime=", 11) == 0) {
|
||||||
const std::string showtimeMode = argv[i] + 11;
|
const std::string showtimeMode = argv[i] + 11;
|
||||||
if (showtimeMode == "file")
|
if (showtimeMode == "file")
|
||||||
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_FILE;
|
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_FILE;
|
||||||
else if (showtimeMode == "summary")
|
else if (showtimeMode == "summary")
|
||||||
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY;
|
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_SUMMARY;
|
||||||
else if (showtimeMode == "top5")
|
else if (showtimeMode == "top5")
|
||||||
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_TOP5;
|
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_TOP5;
|
||||||
else if (showtimeMode.empty())
|
else if (showtimeMode.empty())
|
||||||
mSettings->showtime = SHOWTIME_MODES::SHOWTIME_NONE;
|
mSettings.showtime = SHOWTIME_MODES::SHOWTIME_NONE;
|
||||||
else {
|
else {
|
||||||
printError("unrecognized showtime mode: \"" + showtimeMode + "\". Supported modes: file, summary, top5.");
|
printError("unrecognized showtime mode: \"" + showtimeMode + "\". Supported modes: file, summary, top5.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -825,10 +825,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
const std::string std = argv[i] + 6;
|
const std::string std = argv[i] + 6;
|
||||||
// TODO: print error when standard is unknown
|
// TODO: print error when standard is unknown
|
||||||
if (std::strncmp(std.c_str(), "c++", 3) == 0) {
|
if (std::strncmp(std.c_str(), "c++", 3) == 0) {
|
||||||
mSettings->standards.cpp = Standards::getCPP(std);
|
mSettings.standards.cpp = Standards::getCPP(std);
|
||||||
}
|
}
|
||||||
else if (std::strncmp(std.c_str(), "c", 1) == 0) {
|
else if (std::strncmp(std.c_str(), "c", 1) == 0) {
|
||||||
mSettings->standards.c = Standards::getC(std);
|
mSettings.standards.c = Standards::getC(std);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
printError("unknown --std value '" + std + "'");
|
printError("unknown --std value '" + std + "'");
|
||||||
|
@ -838,7 +838,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
|
else if (std::strncmp(argv[i], "--suppress=", 11) == 0) {
|
||||||
const std::string suppression = argv[i]+11;
|
const std::string suppression = argv[i]+11;
|
||||||
const std::string errmsg(mSettings->nomsg.addSuppressionLine(suppression));
|
const std::string errmsg(mSettings.nomsg.addSuppressionLine(suppression));
|
||||||
if (!errmsg.empty()) {
|
if (!errmsg.empty()) {
|
||||||
printError(errmsg);
|
printError(errmsg);
|
||||||
return false;
|
return false;
|
||||||
|
@ -865,7 +865,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
printError(message);
|
printError(message);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const std::string errmsg(mSettings->nomsg.parseFile(f));
|
const std::string errmsg(mSettings.nomsg.parseFile(f));
|
||||||
if (!errmsg.empty()) {
|
if (!errmsg.empty()) {
|
||||||
printError(errmsg);
|
printError(errmsg);
|
||||||
return false;
|
return false;
|
||||||
|
@ -874,7 +874,7 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--suppress-xml=", 15) == 0) {
|
else if (std::strncmp(argv[i], "--suppress-xml=", 15) == 0) {
|
||||||
const char * filename = argv[i] + 15;
|
const char * filename = argv[i] + 15;
|
||||||
const std::string errmsg(mSettings->nomsg.parseXmlFile(filename));
|
const std::string errmsg(mSettings.nomsg.parseXmlFile(filename));
|
||||||
if (!errmsg.empty()) {
|
if (!errmsg.empty()) {
|
||||||
printError(errmsg);
|
printError(errmsg);
|
||||||
return false;
|
return false;
|
||||||
|
@ -886,32 +886,32 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
std::strncmp(argv[i], "--template=", 11) == 0) {
|
std::strncmp(argv[i], "--template=", 11) == 0) {
|
||||||
// "--template format"
|
// "--template format"
|
||||||
if (argv[i][10] == '=')
|
if (argv[i][10] == '=')
|
||||||
mSettings->templateFormat = argv[i] + 11;
|
mSettings.templateFormat = argv[i] + 11;
|
||||||
else if ((i+1) < argc && argv[i+1][0] != '-') {
|
else if ((i+1) < argc && argv[i+1][0] != '-') {
|
||||||
++i;
|
++i;
|
||||||
mSettings->templateFormat = argv[i];
|
mSettings.templateFormat = argv[i];
|
||||||
} else {
|
} else {
|
||||||
printError("argument to '--template' is missing.");
|
printError("argument to '--template' is missing.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSettings->templateFormat == "gcc") {
|
if (mSettings.templateFormat == "gcc") {
|
||||||
mSettings->templateFormat = "{bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset}\\n{code}";
|
mSettings.templateFormat = "{bold}{file}:{line}:{column}: {magenta}warning:{default} {message} [{id}]{reset}\\n{code}";
|
||||||
mSettings->templateLocation = "{bold}{file}:{line}:{column}: {dim}note:{reset} {info}\\n{code}";
|
mSettings.templateLocation = "{bold}{file}:{line}:{column}: {dim}note:{reset} {info}\\n{code}";
|
||||||
} else if (mSettings->templateFormat == "daca2") {
|
} else if (mSettings.templateFormat == "daca2") {
|
||||||
mSettings->daca = true;
|
mSettings.daca = true;
|
||||||
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
|
mSettings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]";
|
||||||
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}";
|
mSettings.templateLocation = "{file}:{line}:{column}: note: {info}";
|
||||||
} else if (mSettings->templateFormat == "vs")
|
} else if (mSettings.templateFormat == "vs")
|
||||||
mSettings->templateFormat = "{file}({line}): {severity}: {message}";
|
mSettings.templateFormat = "{file}({line}): {severity}: {message}";
|
||||||
else if (mSettings->templateFormat == "edit")
|
else if (mSettings.templateFormat == "edit")
|
||||||
mSettings->templateFormat = "{file} +{line}: {severity}: {message}";
|
mSettings.templateFormat = "{file} +{line}: {severity}: {message}";
|
||||||
else if (mSettings->templateFormat == "cppcheck1")
|
else if (mSettings.templateFormat == "cppcheck1")
|
||||||
mSettings->templateFormat = "{callstack}: ({severity}{inconclusive:, inconclusive}) {message}";
|
mSettings.templateFormat = "{callstack}: ({severity}{inconclusive:, inconclusive}) {message}";
|
||||||
else if (mSettings->templateFormat == "selfcheck") {
|
else if (mSettings.templateFormat == "selfcheck") {
|
||||||
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";
|
mSettings.templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";
|
||||||
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
|
mSettings.templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
|
||||||
mSettings->daca = true;
|
mSettings.daca = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,10 +919,10 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
std::strncmp(argv[i], "--template-location=", 20) == 0) {
|
std::strncmp(argv[i], "--template-location=", 20) == 0) {
|
||||||
// "--template-location format"
|
// "--template-location format"
|
||||||
if (argv[i][19] == '=')
|
if (argv[i][19] == '=')
|
||||||
mSettings->templateLocation = argv[i] + 20;
|
mSettings.templateLocation = argv[i] + 20;
|
||||||
else if ((i+1) < argc && argv[i+1][0] != '-') {
|
else if ((i+1) < argc && argv[i+1][0] != '-') {
|
||||||
++i;
|
++i;
|
||||||
mSettings->templateLocation = argv[i];
|
mSettings.templateLocation = argv[i];
|
||||||
} else {
|
} else {
|
||||||
printError("argument to '--template' is missing.");
|
printError("argument to '--template' is missing.");
|
||||||
return false;
|
return false;
|
||||||
|
@ -930,11 +930,11 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--template-max-time=", 20) == 0) {
|
else if (std::strncmp(argv[i], "--template-max-time=", 20) == 0) {
|
||||||
mSettings->templateMaxTime = std::atoi(argv[i] + 20);
|
mSettings.templateMaxTime = std::atoi(argv[i] + 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--typedef-max-time=", 19) == 0) {
|
else if (std::strncmp(argv[i], "--typedef-max-time=", 19) == 0) {
|
||||||
mSettings->typedefMaxTime = std::atoi(argv[i] + 19);
|
mSettings.typedefMaxTime = std::atoi(argv[i] + 19);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strncmp(argv[i], "--valueflow-max-iterations=", 27) == 0) {
|
else if (std::strncmp(argv[i], "--valueflow-max-iterations=", 27) == 0) {
|
||||||
|
@ -949,41 +949,41 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
printError("argument to '--valueflow-max-iteration' needs to be at least 0.");
|
printError("argument to '--valueflow-max-iteration' needs to be at least 0.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mSettings->valueFlowMaxIterations = static_cast<std::size_t>(tmp);
|
mSettings.valueFlowMaxIterations = static_cast<std::size_t>(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (std::strcmp(argv[i], "-v") == 0 || std::strcmp(argv[i], "--verbose") == 0)
|
else if (std::strcmp(argv[i], "-v") == 0 || std::strcmp(argv[i], "--verbose") == 0)
|
||||||
mSettings->verbose = true;
|
mSettings.verbose = true;
|
||||||
|
|
||||||
else if (std::strcmp(argv[i], "--version") == 0) {
|
else if (std::strcmp(argv[i], "--version") == 0) {
|
||||||
mShowVersion = true;
|
mShowVersion = true;
|
||||||
mExitAfterPrint = true;
|
mExitAfterPrint = true;
|
||||||
mSettings->loadCppcheckCfg();
|
mSettings.loadCppcheckCfg();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write results in results.xml
|
// Write results in results.xml
|
||||||
else if (std::strcmp(argv[i], "--xml") == 0)
|
else if (std::strcmp(argv[i], "--xml") == 0)
|
||||||
mSettings->xml = true;
|
mSettings.xml = true;
|
||||||
|
|
||||||
// Define the XML file version (and enable XML output)
|
// Define the XML file version (and enable XML output)
|
||||||
else if (std::strncmp(argv[i], "--xml-version=", 14) == 0) {
|
else if (std::strncmp(argv[i], "--xml-version=", 14) == 0) {
|
||||||
const std::string numberString(argv[i]+14);
|
const std::string numberString(argv[i]+14);
|
||||||
|
|
||||||
std::istringstream iss(numberString);
|
std::istringstream iss(numberString);
|
||||||
if (!(iss >> mSettings->xml_version)) {
|
if (!(iss >> mSettings.xml_version)) {
|
||||||
printError("argument to '--xml-version' is not a number.");
|
printError("argument to '--xml-version' is not a number.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mSettings->xml_version != 2) {
|
if (mSettings.xml_version != 2) {
|
||||||
// We only have xml version 2
|
// We only have xml version 2
|
||||||
printError("'--xml-version' can only be 2.");
|
printError("'--xml-version' can only be 2.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable also XML if version is set
|
// Enable also XML if version is set
|
||||||
mSettings->xml = true;
|
mSettings.xml = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@ -1000,27 +1000,27 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mSettings->loadCppcheckCfg();
|
mSettings.loadCppcheckCfg();
|
||||||
|
|
||||||
// Default template format..
|
// Default template format..
|
||||||
if (mSettings->templateFormat.empty()) {
|
if (mSettings.templateFormat.empty()) {
|
||||||
mSettings->templateFormat = "{bold}{file}:{line}:{column}: {red}{inconclusive:{magenta}}{severity}:{inconclusive: inconclusive:}{default} {message} [{id}]{reset}\\n{code}";
|
mSettings.templateFormat = "{bold}{file}:{line}:{column}: {red}{inconclusive:{magenta}}{severity}:{inconclusive: inconclusive:}{default} {message} [{id}]{reset}\\n{code}";
|
||||||
if (mSettings->templateLocation.empty())
|
if (mSettings.templateLocation.empty())
|
||||||
mSettings->templateLocation = "{bold}{file}:{line}:{column}: {dim}note:{reset} {info}\\n{code}";
|
mSettings.templateLocation = "{bold}{file}:{line}:{column}: {dim}note:{reset} {info}\\n{code}";
|
||||||
}
|
}
|
||||||
|
|
||||||
mSettings->project.ignorePaths(mIgnoredPaths);
|
mSettings.project.ignorePaths(mIgnoredPaths);
|
||||||
|
|
||||||
if (mSettings->force || maxconfigs)
|
if (mSettings.force || maxconfigs)
|
||||||
mSettings->checkAllConfigurations = true;
|
mSettings.checkAllConfigurations = true;
|
||||||
|
|
||||||
if (mSettings->force)
|
if (mSettings.force)
|
||||||
mSettings->maxConfigs = INT_MAX;
|
mSettings.maxConfigs = INT_MAX;
|
||||||
|
|
||||||
else if ((def || mSettings->preprocessOnly) && !maxconfigs)
|
else if ((def || mSettings.preprocessOnly) && !maxconfigs)
|
||||||
mSettings->maxConfigs = 1U;
|
mSettings.maxConfigs = 1U;
|
||||||
|
|
||||||
if (mSettings->checks.isEnabled(Checks::unusedFunction) && mSettings->jobs > 1) {
|
if (mSettings.checks.isEnabled(Checks::unusedFunction) && mSettings.jobs > 1) {
|
||||||
printMessage("unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
|
printMessage("unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1043,14 +1043,14 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Print error only if we have "real" command and expect files
|
// Print error only if we have "real" command and expect files
|
||||||
if (!mExitAfterPrint && mPathNames.empty() && mSettings->project.fileSettings.empty()) {
|
if (!mExitAfterPrint && mPathNames.empty() && mSettings.project.fileSettings.empty()) {
|
||||||
printError("no C or C++ source files found.");
|
printError("no C or C++ source files found.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use paths _pathnames if no base paths for relative path output are given
|
// Use paths _pathnames if no base paths for relative path output are given
|
||||||
if (mSettings->basePaths.empty() && mSettings->relativePaths)
|
if (mSettings.basePaths.empty() && mSettings.relativePaths)
|
||||||
mSettings->basePaths = mPathNames;
|
mSettings.basePaths = mPathNames;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1381,7 +1381,7 @@ void CmdLineParser::printHelp()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CmdLineParser::isCppcheckPremium() const {
|
bool CmdLineParser::isCppcheckPremium() const {
|
||||||
if (mSettings->cppcheckCfgProductName.empty())
|
if (mSettings.cppcheckCfgProductName.empty())
|
||||||
mSettings->loadCppcheckCfg();
|
mSettings.loadCppcheckCfg();
|
||||||
return mSettings->cppcheckCfgProductName.compare(0, 16, "Cppcheck Premium") == 0;
|
return mSettings.cppcheckCfgProductName.compare(0, 16, "Cppcheck Premium") == 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public:
|
||||||
* @param settings Settings instance that will be modified according to
|
* @param settings Settings instance that will be modified according to
|
||||||
* options user has given.
|
* options user has given.
|
||||||
*/
|
*/
|
||||||
explicit CmdLineParser(Settings *settings);
|
explicit CmdLineParser(Settings &settings);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse given command line.
|
* Parse given command line.
|
||||||
|
@ -120,7 +120,7 @@ private:
|
||||||
|
|
||||||
std::vector<std::string> mPathNames;
|
std::vector<std::string> mPathNames;
|
||||||
std::vector<std::string> mIgnoredPaths;
|
std::vector<std::string> mIgnoredPaths;
|
||||||
Settings *mSettings;
|
Settings &mSettings;
|
||||||
bool mShowHelp;
|
bool mShowHelp;
|
||||||
bool mShowVersion;
|
bool mShowVersion;
|
||||||
bool mShowErrorMessages;
|
bool mShowErrorMessages;
|
||||||
|
|
|
@ -82,7 +82,7 @@ CppCheckExecutor::~CppCheckExecutor()
|
||||||
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])
|
bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* const argv[])
|
||||||
{
|
{
|
||||||
Settings& settings = cppcheck->settings();
|
Settings& settings = cppcheck->settings();
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
const bool success = parser.parseFromArgs(argc, argv);
|
const bool success = parser.parseFromArgs(argc, argv);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|
|
@ -38,7 +38,7 @@ class TestCmdlineParser : public TestFixture {
|
||||||
public:
|
public:
|
||||||
TestCmdlineParser()
|
TestCmdlineParser()
|
||||||
: TestFixture("TestCmdlineParser")
|
: TestFixture("TestCmdlineParser")
|
||||||
, defParser(&settings) {
|
, defParser(settings) {
|
||||||
#if defined(_WIN64) || defined(_WIN32)
|
#if defined(_WIN64) || defined(_WIN32)
|
||||||
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
|
CmdLineParser::SHOW_DEF_PLATFORM_MSG = false;
|
||||||
#endif
|
#endif
|
||||||
|
@ -206,7 +206,7 @@ private:
|
||||||
void nooptions() {
|
void nooptions() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck"};
|
const char * const argv[] = {"cppcheck"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(1, argv));
|
ASSERT(parser.parseFromArgs(1, argv));
|
||||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||||
ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0);
|
ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0);
|
||||||
|
@ -215,7 +215,7 @@ private:
|
||||||
void helpshort() {
|
void helpshort() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-h"};
|
const char * const argv[] = {"cppcheck", "-h"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(2, argv));
|
ASSERT(parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||||
ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0);
|
ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0);
|
||||||
|
@ -224,7 +224,7 @@ private:
|
||||||
void helplong() {
|
void helplong() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "--help"};
|
const char * const argv[] = {"cppcheck", "--help"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(2, argv));
|
ASSERT(parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS(true, parser.getShowHelp());
|
ASSERT_EQUALS(true, parser.getShowHelp());
|
||||||
ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0);
|
ASSERT(GET_REDIRECT_OUTPUT.find("Cppcheck - A tool for static C/C++ code analysis") == 0);
|
||||||
|
@ -233,7 +233,7 @@ private:
|
||||||
void showversion() {
|
void showversion() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "--version"};
|
const char * const argv[] = {"cppcheck", "--version"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(2, argv));
|
ASSERT(parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS(true, parser.getShowVersion());
|
ASSERT_EQUALS(true, parser.getShowVersion());
|
||||||
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); // version is not actually shown
|
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT); // version is not actually shown
|
||||||
|
@ -242,7 +242,7 @@ private:
|
||||||
void onefile() {
|
void onefile() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(2, argv));
|
ASSERT(parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
||||||
ASSERT_EQUALS("file.cpp", parser.getPathNames().at(0));
|
ASSERT_EQUALS("file.cpp", parser.getPathNames().at(0));
|
||||||
|
@ -252,7 +252,7 @@ private:
|
||||||
void onepath() {
|
void onepath() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "src"};
|
const char * const argv[] = {"cppcheck", "src"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(2, argv));
|
ASSERT(parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
ASSERT_EQUALS(1, (int)parser.getPathNames().size());
|
||||||
ASSERT_EQUALS("src", parser.getPathNames().at(0));
|
ASSERT_EQUALS("src", parser.getPathNames().at(0));
|
||||||
|
@ -262,7 +262,7 @@ private:
|
||||||
void optionwithoutfile() {
|
void optionwithoutfile() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-v"};
|
const char * const argv[] = {"cppcheck", "-v"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS(0, (int)parser.getPathNames().size());
|
ASSERT_EQUALS(0, (int)parser.getPathNames().size());
|
||||||
ASSERT_EQUALS("cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
|
ASSERT_EQUALS("cppcheck: error: no C or C++ source files found.\n", GET_REDIRECT_OUTPUT);
|
||||||
|
@ -1359,7 +1359,7 @@ private:
|
||||||
void ignorepathsnopath() {
|
void ignorepathsnopath() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-i"};
|
const char * const argv[] = {"cppcheck", "-i"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
// Fails since no ignored path given
|
// Fails since no ignored path given
|
||||||
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
ASSERT_EQUALS(false, parser.parseFromArgs(2, argv));
|
||||||
ASSERT_EQUALS("cppcheck: error: argument to '-i' is missing.\n", GET_REDIRECT_OUTPUT);
|
ASSERT_EQUALS("cppcheck: error: argument to '-i' is missing.\n", GET_REDIRECT_OUTPUT);
|
||||||
|
@ -1482,7 +1482,7 @@ private:
|
||||||
void ignorepaths1() {
|
void ignorepaths1() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "-isrc", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(3, argv));
|
ASSERT(parser.parseFromArgs(3, argv));
|
||||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||||
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
||||||
|
@ -1492,7 +1492,7 @@ private:
|
||||||
void ignorepaths2() {
|
void ignorepaths2() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "-i", "src", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(4, argv));
|
ASSERT(parser.parseFromArgs(4, argv));
|
||||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||||
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
||||||
|
@ -1502,7 +1502,7 @@ private:
|
||||||
void ignorepaths3() {
|
void ignorepaths3() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "-isrc", "-imodule", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(4, argv));
|
ASSERT(parser.parseFromArgs(4, argv));
|
||||||
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
||||||
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
||||||
|
@ -1513,7 +1513,7 @@ private:
|
||||||
void ignorepaths4() {
|
void ignorepaths4() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "-i", "src", "-i", "module", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(6, argv));
|
ASSERT(parser.parseFromArgs(6, argv));
|
||||||
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
ASSERT_EQUALS(2, parser.getIgnoredPaths().size());
|
||||||
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
ASSERT_EQUALS("src", parser.getIgnoredPaths()[0]);
|
||||||
|
@ -1524,7 +1524,7 @@ private:
|
||||||
void ignorefilepaths1() {
|
void ignorefilepaths1() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "-ifoo.cpp", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(3, argv));
|
ASSERT(parser.parseFromArgs(3, argv));
|
||||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||||
ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]);
|
ASSERT_EQUALS("foo.cpp", parser.getIgnoredPaths()[0]);
|
||||||
|
@ -1534,7 +1534,7 @@ private:
|
||||||
void ignorefilepaths2() {
|
void ignorefilepaths2() {
|
||||||
REDIRECT;
|
REDIRECT;
|
||||||
const char * const argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
|
const char * const argv[] = {"cppcheck", "-isrc/foo.cpp", "file.cpp"};
|
||||||
CmdLineParser parser(&settings);
|
CmdLineParser parser(settings);
|
||||||
ASSERT(parser.parseFromArgs(3, argv));
|
ASSERT(parser.parseFromArgs(3, argv));
|
||||||
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
ASSERT_EQUALS(1, parser.getIgnoredPaths().size());
|
||||||
ASSERT_EQUALS("src/foo.cpp", parser.getIgnoredPaths()[0]);
|
ASSERT_EQUALS("src/foo.cpp", parser.getIgnoredPaths()[0]);
|
||||||
|
|
Loading…
Reference in New Issue