Skip to content

Commit

Permalink
Refactorization: Reimplemented Settings::_enabled as a bitfeld instea…
Browse files Browse the repository at this point in the history
…d of std::set (#7995)
  • Loading branch information
PKEuS committed Apr 11, 2017
1 parent 4d1a643 commit b1f4bd7
Show file tree
Hide file tree
Showing 32 changed files with 285 additions and 248 deletions.
4 changes: 2 additions & 2 deletions cli/cmdlineparser.cpp
Expand Up @@ -325,7 +325,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
return false;
}
// when "style" is enabled, also enable "warning", "performance" and "portability"
if (_settings->isEnabled("style")) {
if (_settings->isEnabled(Settings::STYLE)) {
_settings->addEnabled("warning");
_settings->addEnabled("performance");
_settings->addEnabled("portability");
Expand Down Expand Up @@ -759,7 +759,7 @@ bool CmdLineParser::ParseFromArgs(int argc, const char* const argv[])
else if ((def || _settings->preprocessOnly) && !maxconfigs)
_settings->maxConfigs = 1U;

if (_settings->isEnabled("unusedFunction") && _settings->jobs > 1) {
if (_settings->isEnabled(Settings::UNUSED_FUNCTION) && _settings->jobs > 1) {
PrintMessage("cppcheck: unusedFunction check can't be used with '-j' option. Disabling unusedFunction check.");
}

Expand Down
6 changes: 3 additions & 3 deletions cli/cppcheckexecutor.cpp
Expand Up @@ -119,7 +119,7 @@ bool CppCheckExecutor::parseFromArgs(CppCheck *cppcheck, int argc, const char* c
++iter;
else {
// If the include path is not found, warn user and remove the non-existing path from the list.
if (settings.isEnabled("information"))
if (settings.isEnabled(Settings::INFORMATION))
std::cout << "(information) Couldn't find path given by -I '" << path << '\'' << std::endl;
iter = settings.includePaths.erase(iter);
}
Expand Down Expand Up @@ -864,7 +864,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha

cppcheck.analyseWholeProgram(_settings->buildDir, _files);

if (settings.isEnabled("information") || settings.checkConfiguration) {
if (settings.isEnabled(Settings::INFORMATION) || settings.checkConfiguration) {
const bool enableUnusedFunctionCheck = cppcheck.isUnusedFunctionCheckEnabled();

if (settings.jointSuppressionReport) {
Expand All @@ -879,7 +879,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
if (!settings.checkConfiguration) {
cppcheck.tooManyConfigsError("",0U);

if (settings.isEnabled("missingInclude") && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
if (settings.isEnabled(Settings::MISSING_INCLUDE) && (Preprocessor::missingIncludeFlag || Preprocessor::missingSystemIncludeFlag)) {
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
ErrorLogger::ErrorMessage msg(callStack,
emptyString,
Expand Down
2 changes: 1 addition & 1 deletion lib/check64bit.cpp
Expand Up @@ -36,7 +36,7 @@ namespace {

void Check64BitPortability::pointerassignment()
{
if (!_settings->isEnabled("portability"))
if (!_settings->isEnabled(Settings::PORTABILITY))
return;

const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
Expand Down
2 changes: 1 addition & 1 deletion lib/checkassert.cpp
Expand Up @@ -35,7 +35,7 @@ namespace {

void CheckAssert::assertWithSideEffects()
{
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

for (const Token* tok = _tokenizer->list.front(); tok; tok = tok->next()) {
Expand Down
4 changes: 2 additions & 2 deletions lib/checkautovariables.cpp
Expand Up @@ -168,8 +168,8 @@ static bool variableIsUsedInScope(const Token* start, unsigned int varId, const

void CheckAutoVariables::assignFunctionArg()
{
const bool printStyle = _settings->isEnabled("style");
const bool printWarning = _settings->isEnabled("warning");
const bool printStyle = _settings->isEnabled(Settings::STYLE);
const bool printWarning = _settings->isEnabled(Settings::WARNING);
if (!printStyle && !printWarning)
return;

Expand Down
14 changes: 7 additions & 7 deletions lib/checkbool.cpp
Expand Up @@ -46,7 +46,7 @@ static bool isNonBoolStdType(const Variable* var)
//---------------------------------------------------------------------------
void CheckBool::checkIncrementBoolean()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
Expand Down Expand Up @@ -81,7 +81,7 @@ void CheckBool::incrementBooleanError(const Token *tok)
//---------------------------------------------------------------------------
void CheckBool::checkBitwiseOnBoolean()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

// danmar: this is inconclusive because I don't like that there are
Expand Down Expand Up @@ -125,7 +125,7 @@ void CheckBool::bitwiseOnBooleanError(const Token *tok, const std::string &varna

void CheckBool::checkComparisonOfBoolWithInt()
{
if (!_settings->isEnabled("warning") || !_tokenizer->isCPP())
if (!_settings->isEnabled(Settings::WARNING) || !_tokenizer->isCPP())
return;

const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase();
Expand Down Expand Up @@ -176,7 +176,7 @@ static bool tokenIsFunctionReturningBool(const Token* tok)

void CheckBool::checkComparisonOfFuncReturningBool()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

if (!_tokenizer->isCPP())
Expand Down Expand Up @@ -240,7 +240,7 @@ void CheckBool::checkComparisonOfBoolWithBool()
if (!_settings->experimental)
return;

if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

if (!_tokenizer->isCPP())
Expand Down Expand Up @@ -319,7 +319,7 @@ void CheckBool::assignBoolToPointerError(const Token *tok)
//-----------------------------------------------------------------------------
void CheckBool::checkComparisonOfBoolExpressionWithInt()
{
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

const SymbolDatabase* symbolDatabase = _tokenizer->getSymbolDatabase();
Expand Down Expand Up @@ -437,7 +437,7 @@ void CheckBool::checkAssignBoolToFloat()
{
if (!_tokenizer->isCPP())
return;
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;
const SymbolDatabase *symbolDatabase = _tokenizer->getSymbolDatabase();
const std::size_t functions = symbolDatabase->functionScopes.size();
Expand Down
16 changes: 8 additions & 8 deletions lib/checkbufferoverrun.cpp
Expand Up @@ -84,7 +84,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
}

if (condition != nullptr) {
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

std::ostringstream errmsg;
Expand Down Expand Up @@ -169,7 +169,7 @@ void CheckBufferOverrun::possibleBufferOverrunError(const Token *tok, const std:

void CheckBufferOverrun::strncatUsageError(const Token *tok)
{
if (_settings && !_settings->isEnabled("warning"))
if (_settings && !_settings->isEnabled(Settings::WARNING))
return;

reportError(tok, Severity::warning, "strncatUsage",
Expand Down Expand Up @@ -220,7 +220,7 @@ void CheckBufferOverrun::pointerOutOfBoundsError(const Token *tok, const Token *

void CheckBufferOverrun::sizeArgumentAsCharError(const Token *tok)
{
if (_settings && !_settings->isEnabled("warning"))
if (_settings && !_settings->isEnabled(Settings::WARNING))
return;
reportError(tok, Severity::warning, "sizeArgumentAsChar", "The size argument is given as a char constant.", CWE682, false);
}
Expand Down Expand Up @@ -474,7 +474,7 @@ void CheckBufferOverrun::checkFunctionParameter(const Token &ftok, unsigned int
}

// Check 'float x[10]' arguments in declaration
if (_settings->isEnabled("warning")) {
if (_settings->isEnabled(Settings::WARNING)) {
const Function* const func = ftok.function();

// If argument is '%type% a[num]' then check bounds against num
Expand Down Expand Up @@ -575,7 +575,7 @@ void CheckBufferOverrun::checkScope(const Token *tok, const std::vector<const st
// out of bounds then this flag will be set.
bool pointerIsOutOfBounds = false;

const bool printPortability = _settings->isEnabled("portability");
const bool printPortability = _settings->isEnabled(Settings::PORTABILITY);

for (const Token* const end = tok->scope()->classEnd; tok && tok != end; tok = tok->next()) {
if (declarationId != 0 && Token::Match(tok, "%varid% = new|malloc|realloc", declarationId)) {
Expand Down Expand Up @@ -905,8 +905,8 @@ void CheckBufferOverrun::checkScope(const Token *tok, std::map<unsigned int, Arr

void CheckBufferOverrun::checkScope_inner(const Token *tok, const ArrayInfo &arrayInfo)
{
const bool printPortability = _settings->isEnabled("portability");
const bool printWarning = _settings->isEnabled("warning");
const bool printPortability = _settings->isEnabled(Settings::PORTABILITY);
const bool printWarning = _settings->isEnabled(Settings::WARNING);
const bool printInconclusive = _settings->inconclusive;

if (tok->strAt(1) == "[") {
Expand Down Expand Up @@ -1853,7 +1853,7 @@ MathLib::bigint CheckBufferOverrun::ArrayInfo::totalIndex(const std::vector<Valu

void CheckBufferOverrun::arrayIndexThenCheck()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t functions = symbolDatabase->functionScopes.size();
Expand Down
36 changes: 18 additions & 18 deletions lib/checkclass.cpp
Expand Up @@ -80,8 +80,8 @@ CheckClass::CheckClass(const Tokenizer *tokenizer, const Settings *settings, Err

void CheckClass::constructors()
{
const bool printStyle = _settings->isEnabled("style");
const bool printWarnings = _settings->isEnabled("warning");
const bool printStyle = _settings->isEnabled(Settings::STYLE);
const bool printWarnings = _settings->isEnabled(Settings::WARNING);
if (!printStyle && !printWarnings)
return;

Expand Down Expand Up @@ -238,7 +238,7 @@ void CheckClass::constructors()

void CheckClass::checkExplicitConstructors()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -286,7 +286,7 @@ void CheckClass::checkExplicitConstructors()

void CheckClass::copyconstructors()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -833,7 +833,7 @@ void CheckClass::operatorEqVarError(const Token *tok, const std::string &classna

void CheckClass::initializationListUsage()
{
if (!_settings->isEnabled("performance"))
if (!_settings->isEnabled(Settings::PERFORMANCE))
return;

const std::size_t functions = symbolDatabase->functionScopes.size();
Expand Down Expand Up @@ -948,7 +948,7 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)

void CheckClass::privateFunctions()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -1018,7 +1018,7 @@ static const Scope* findFunctionOf(const Scope* scope)

void CheckClass::checkMemset()
{
const bool printWarnings = _settings->isEnabled("warning");
const bool printWarnings = _settings->isEnabled(Settings::WARNING);
const std::size_t functions = symbolDatabase->functionScopes.size();
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
Expand Down Expand Up @@ -1105,7 +1105,7 @@ void CheckClass::checkMemsetType(const Scope *start, const Token *tok, const Sco
return;
parsedTypes.insert(type);

const bool printPortability = _settings->isEnabled("portability");
const bool printPortability = _settings->isEnabled(Settings::PORTABILITY);

// recursively check all parent classes
for (std::size_t i = 0; i < type->definedType->derivedFrom.size(); i++) {
Expand Down Expand Up @@ -1209,7 +1209,7 @@ void CheckClass::memsetErrorFloat(const Token *tok, const std::string &type)

void CheckClass::operatorEq()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -1263,7 +1263,7 @@ void CheckClass::operatorEqReturnError(const Token *tok, const std::string &clas

void CheckClass::operatorEqRetRefThis()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -1399,7 +1399,7 @@ void CheckClass::operatorEqMissingReturnStatementError(const Token *tok, bool er

void CheckClass::operatorEqToSelf()
{
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -1648,7 +1648,7 @@ void CheckClass::virtualDestructor()
void CheckClass::virtualDestructorError(const Token *tok, const std::string &Base, const std::string &Derived, bool inconclusive)
{
if (inconclusive) {
if (_settings->isEnabled("warning"))
if (_settings->isEnabled(Settings::WARNING))
reportError(tok, Severity::warning, "virtualDestructor", "Class '" + Base + "' which has virtual members does not have a virtual destructor.", CWE404, true);
} else {
reportError(tok, Severity::error, "virtualDestructor", "Class '" + Base + "' which is inherited by class '" + Derived + "' does not have a virtual destructor.\n"
Expand All @@ -1665,7 +1665,7 @@ void CheckClass::virtualDestructorError(const Token *tok, const std::string &Bas

void CheckClass::thisSubtraction()
{
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

const Token *tok = _tokenizer->tokens();
Expand Down Expand Up @@ -1696,7 +1696,7 @@ void CheckClass::checkConst()
if (!_settings->inconclusive)
return;

if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down Expand Up @@ -2075,7 +2075,7 @@ namespace { // avoid one-definition-rule violation

void CheckClass::initializerListOrder()
{
if (!_settings->isEnabled("style"))
if (!_settings->isEnabled(Settings::STYLE))
return;

// This check is not inconclusive. However it only determines if the initialization
Expand Down Expand Up @@ -2183,7 +2183,7 @@ void CheckClass::selfInitializationError(const Token* tok, const std::string& va

void CheckClass::checkPureVirtualFunctionCall()
{
if (! _settings->isEnabled("warning"))
if (! _settings->isEnabled(Settings::WARNING))
return;
const std::size_t functions = symbolDatabase->functionScopes.size();
std::map<const Function *, std::list<const Token *> > callsPureVirtualFunctionMap;
Expand Down Expand Up @@ -2305,7 +2305,7 @@ void CheckClass::callsPureVirtualFunctionError(

void CheckClass::checkDuplInheritedMembers()
{
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

// Iterate over all classes
Expand Down Expand Up @@ -2359,7 +2359,7 @@ void CheckClass::duplInheritedMembersError(const Token *tok1, const Token* tok2,

void CheckClass::checkCopyCtorAndEqOperator()
{
if (!_settings->isEnabled("warning"))
if (!_settings->isEnabled(Settings::WARNING))
return;

const std::size_t classes = symbolDatabase->classAndStructScopes.size();
Expand Down

0 comments on commit b1f4bd7

Please sign in to comment.