|
Packit |
2035a7 |
/*
|
|
Packit |
2035a7 |
* Cppcheck - A tool for static C/C++ code analysis
|
|
Packit |
2035a7 |
* Copyright (C) 2007-2017 Cppcheck team.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is free software: you can redistribute it and/or modify
|
|
Packit |
2035a7 |
* it under the terms of the GNU General Public License as published by
|
|
Packit |
2035a7 |
* the Free Software Foundation, either version 3 of the License, or
|
|
Packit |
2035a7 |
* (at your option) any later version.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* This program is distributed in the hope that it will be useful,
|
|
Packit |
2035a7 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
2035a7 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
2035a7 |
* GNU General Public License for more details.
|
|
Packit |
2035a7 |
*
|
|
Packit |
2035a7 |
* You should have received a copy of the GNU General Public License
|
|
Packit |
2035a7 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
Packit |
2035a7 |
*/
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include "settings.h"
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
#include "valueflow.h"
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
bool Settings::_terminated;
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
Settings::Settings()
|
|
Packit |
2035a7 |
: _enabled(0),
|
|
Packit |
2035a7 |
debug(false),
|
|
Packit |
2035a7 |
debugnormal(false),
|
|
Packit |
2035a7 |
debugwarnings(false),
|
|
Packit |
2035a7 |
dump(false),
|
|
Packit |
2035a7 |
exceptionHandling(false),
|
|
Packit |
2035a7 |
inconclusive(false),
|
|
Packit |
2035a7 |
jointSuppressionReport(false),
|
|
Packit |
2035a7 |
experimental(false),
|
|
Packit |
2035a7 |
quiet(false),
|
|
Packit |
2035a7 |
inlineSuppressions(false),
|
|
Packit |
2035a7 |
verbose(false),
|
|
Packit |
2035a7 |
force(false),
|
|
Packit |
2035a7 |
relativePaths(false),
|
|
Packit |
2035a7 |
xml(false), xml_version(2),
|
|
Packit |
2035a7 |
jobs(1),
|
|
Packit |
2035a7 |
loadAverage(0),
|
|
Packit |
2035a7 |
exitCode(0),
|
|
Packit |
2035a7 |
showtime(SHOWTIME_NONE),
|
|
Packit |
2035a7 |
preprocessOnly(false),
|
|
Packit |
2035a7 |
maxConfigs(12),
|
|
Packit |
2035a7 |
enforcedLang(None),
|
|
Packit |
2035a7 |
reportProgress(false),
|
|
Packit |
2035a7 |
checkConfiguration(false),
|
|
Packit |
2035a7 |
checkLibrary(false)
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
std::string Settings::addEnabled(const std::string &str)
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
// Enable parameters may be comma separated...
|
|
Packit |
2035a7 |
if (str.find(',') != std::string::npos) {
|
|
Packit |
2035a7 |
std::string::size_type prevPos = 0;
|
|
Packit |
2035a7 |
std::string::size_type pos = 0;
|
|
Packit |
2035a7 |
while ((pos = str.find(',', pos)) != std::string::npos) {
|
|
Packit |
2035a7 |
if (pos == prevPos)
|
|
Packit |
2035a7 |
return std::string("cppcheck: --enable parameter is empty");
|
|
Packit |
2035a7 |
const std::string errmsg(addEnabled(str.substr(prevPos, pos - prevPos)));
|
|
Packit |
2035a7 |
if (!errmsg.empty())
|
|
Packit |
2035a7 |
return errmsg;
|
|
Packit |
2035a7 |
++pos;
|
|
Packit |
2035a7 |
prevPos = pos;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
if (prevPos >= str.length())
|
|
Packit |
2035a7 |
return std::string("cppcheck: --enable parameter is empty");
|
|
Packit |
2035a7 |
return addEnabled(str.substr(prevPos));
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
if (str == "all") {
|
|
Packit |
2035a7 |
_enabled |= WARNING | STYLE | PERFORMANCE | PORTABILITY | INFORMATION | UNUSED_FUNCTION | MISSING_INCLUDE;
|
|
Packit |
2035a7 |
} else if (str == "warning") {
|
|
Packit |
2035a7 |
_enabled |= WARNING;
|
|
Packit |
2035a7 |
} else if (str == "style") {
|
|
Packit |
2035a7 |
_enabled |= STYLE;
|
|
Packit |
2035a7 |
} else if (str == "performance") {
|
|
Packit |
2035a7 |
_enabled |= PERFORMANCE;
|
|
Packit |
2035a7 |
} else if (str == "portability") {
|
|
Packit |
2035a7 |
_enabled |= PORTABILITY;
|
|
Packit |
2035a7 |
} else if (str == "information") {
|
|
Packit |
2035a7 |
_enabled |= INFORMATION | MISSING_INCLUDE;
|
|
Packit |
2035a7 |
} else if (str == "unusedFunction") {
|
|
Packit |
2035a7 |
_enabled |= UNUSED_FUNCTION;
|
|
Packit |
2035a7 |
} else if (str == "missingInclude") {
|
|
Packit |
2035a7 |
_enabled |= MISSING_INCLUDE;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
#ifdef CHECK_INTERNAL
|
|
Packit |
2035a7 |
else if (str == "internal") {
|
|
Packit |
2035a7 |
_enabled |= INTERNAL;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
#endif
|
|
Packit |
2035a7 |
else {
|
|
Packit |
2035a7 |
if (str.empty())
|
|
Packit |
2035a7 |
return std::string("cppcheck: --enable parameter is empty");
|
|
Packit |
2035a7 |
else
|
|
Packit |
2035a7 |
return std::string("cppcheck: there is no --enable parameter with the name '" + str + "'");
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
return std::string();
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
bool Settings::isEnabled(Severity::SeverityType severity) const
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
switch (severity) {
|
|
Packit |
2035a7 |
case Severity::none:
|
|
Packit |
2035a7 |
return true;
|
|
Packit |
2035a7 |
case Severity::error:
|
|
Packit |
2035a7 |
return true;
|
|
Packit |
2035a7 |
case Severity::warning:
|
|
Packit |
2035a7 |
return isEnabled(WARNING);
|
|
Packit |
2035a7 |
case Severity::style:
|
|
Packit |
2035a7 |
return isEnabled(STYLE);
|
|
Packit |
2035a7 |
case Severity::performance:
|
|
Packit |
2035a7 |
return isEnabled(PERFORMANCE);
|
|
Packit |
2035a7 |
case Severity::portability:
|
|
Packit |
2035a7 |
return isEnabled(PORTABILITY);
|
|
Packit |
2035a7 |
case Severity::information:
|
|
Packit |
2035a7 |
return isEnabled(INFORMATION);
|
|
Packit |
2035a7 |
case Severity::debug:
|
|
Packit |
2035a7 |
return false;
|
|
Packit |
2035a7 |
default:
|
|
Packit |
2035a7 |
return false;
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
}
|
|
Packit |
2035a7 |
|
|
Packit |
2035a7 |
bool Settings::isEnabled(const ValueFlow::Value *value, bool inconclusiveCheck) const
|
|
Packit |
2035a7 |
{
|
|
Packit |
2035a7 |
if (!isEnabled(Settings::WARNING) && (value->condition || value->defaultArg))
|
|
Packit |
2035a7 |
return false;
|
|
Packit |
2035a7 |
if (!inconclusive && (inconclusiveCheck || value->isInconclusive()))
|
|
Packit |
2035a7 |
return false;
|
|
Packit |
2035a7 |
return true;
|
|
Packit |
2035a7 |
}
|