Refactoring: Convert enums to enum classes

This commit is contained in:
amai2012 2019-08-02 21:14:29 +02:00
parent d2b9c1f15a
commit f02636e995
8 changed files with 28 additions and 28 deletions

View File

@ -175,7 +175,7 @@ bool isConstVarExpression(const Token *tok);
const Variable *getLHSVariable(const Token *tok);
struct PathAnalysis {
enum Progress {
enum class Progress {
Continue,
Break
};

View File

@ -69,7 +69,7 @@ static const char * getFunctionTypeName(Function::Type type)
static bool isVariableCopyNeeded(const Variable &var)
{
return var.isPointer() || (var.type() && var.type()->needInitialization == Type::True) || (var.valueType()->type >= ValueType::Type::CHAR);
return var.isPointer() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True) || (var.valueType()->type >= ValueType::Type::CHAR);
}
//---------------------------------------------------------------------------
@ -117,7 +117,7 @@ void CheckClass::constructors()
initTok = initTok->linkAt(1);
if (var.isPrivate() && !var.isStatic() && !Token::Match(var.nameToken(), "%varid% ; %varid% =", var.declarationId()) &&
!Token::Match(initTok, "%var%|] {|=") &&
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::True))) {
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
break;
}
@ -175,7 +175,7 @@ void CheckClass::constructors()
if (usage[count].assign || usage[count].init || var.isStatic())
continue;
if (var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::False && var.type()->derivedFrom.empty())
if (var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::NeedInitialization::False && var.type()->derivedFrom.empty())
continue;
if (var.isConst() && func.isOperator()) // We can't set const members in assignment operator
@ -189,7 +189,7 @@ void CheckClass::constructors()
// Known type that doesn't need initialization or
// known type that has member variables of an unknown type
else if (var.type()->needInitialization != Type::True)
else if (var.type()->needInitialization != Type::NeedInitialization::True)
continue;
}

View File

@ -69,7 +69,7 @@ static bool isAutoDealloc(const Variable *var)
/** @todo false negative: check base class for side effects */
/** @todo false negative: check constructors for side effects */
if (var->typeScope() && var->typeScope()->numConstructors == 0 &&
(var->typeScope()->varlist.empty() || var->type()->needInitialization == Type::True) &&
(var->typeScope()->varlist.empty() || var->type()->needInitialization == Type::NeedInitialization::True) &&
var->type()->derivedFrom.empty())
return false;

View File

@ -99,7 +99,7 @@ void CheckUninitVar::check()
void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDefs)
{
for (const Variable &var : scope->varlist) {
if ((mTokenizer->isCPP() && var.type() && !var.isPointer() && var.type()->needInitialization != Type::True) ||
if ((mTokenizer->isCPP() && var.type() && !var.isPointer() && var.type()->needInitialization != Type::NeedInitialization::True) ||
var.isStatic() || var.isExtern() || var.isReference())
continue;
@ -197,7 +197,7 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar)
if (scope2->className == typeToken->str() && scope2->numConstructors == 0U) {
for (const Variable &var : scope2->varlist) {
if (var.isStatic() || var.hasDefault() || var.isArray() ||
(!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True)))
(!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::NeedInitialization::True)))
continue;
// is the variable declared in a inner union?
@ -693,7 +693,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
continue;
}
}
if (var.isPointer() && (var.typeStartToken()->isStandardType() || var.typeStartToken()->isEnumType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::simpleMatch(tok->next(), "= new")) {
if (var.isPointer() && (var.typeStartToken()->isStandardType() || var.typeStartToken()->isEnumType() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True)) && Token::simpleMatch(tok->next(), "= new")) {
*alloc = CTOR_CALL;
// type has constructor(s)

View File

@ -1376,7 +1376,7 @@ bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type)
return withoutSideEffects;
if (type && type->classScope && type->classScope->numConstructors == 0 &&
(type->classScope->varlist.empty() || type->needInitialization == Type::True)) {
(type->classScope->varlist.empty() || type->needInitialization == Type::NeedInitialization::True)) {
for (std::vector<Type::BaseInfo>::const_iterator i = type->derivedFrom.begin(); i != type->derivedFrom.end(); ++i) {
if (!isRecordTypeWithoutSideEffects(i->type)) {
withoutSideEffects=false;

View File

@ -826,7 +826,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
Scope *scope = &(*it);
if (scope->definedType)
scope->definedType->needInitialization = Type::True;
scope->definedType->needInitialization = Type::NeedInitialization::True;
}
} else {
// For C++, it is more difficult: Determine if user defined type needs initialization...
@ -844,7 +844,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
scope->definedType = &mBlankTypes.back();
}
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::Unknown) {
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::NeedInitialization::Unknown) {
// check for default constructor
bool hasDefaultConstructor = false;
@ -870,7 +870,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
// We assume the default constructor initializes everything.
// Another check will figure out if the constructor actually initializes everything.
if (hasDefaultConstructor)
scope->definedType->needInitialization = Type::False;
scope->definedType->needInitialization = Type::NeedInitialization::False;
// check each member variable to see if it needs initialization
else {
@ -882,9 +882,9 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
if (var->isClass()) {
if (var->type()) {
// does this type need initialization?
if (var->type()->needInitialization == Type::True)
if (var->type()->needInitialization == Type::NeedInitialization::True)
needInitialization = true;
else if (var->type()->needInitialization == Type::Unknown) {
else if (var->type()->needInitialization == Type::NeedInitialization::Unknown) {
if (!(var->valueType() && var->valueType()->type == ValueType::CONTAINER))
unknown = true;
}
@ -894,16 +894,16 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
}
if (needInitialization)
scope->definedType->needInitialization = Type::True;
scope->definedType->needInitialization = Type::NeedInitialization::True;
else if (!unknown)
scope->definedType->needInitialization = Type::False;
scope->definedType->needInitialization = Type::NeedInitialization::False;
else {
if (scope->definedType->needInitialization == Type::Unknown)
if (scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
unknowns++;
}
}
} else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::Unknown)
scope->definedType->needInitialization = Type::True;
} else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
scope->definedType->needInitialization = Type::NeedInitialization::True;
}
retry++;
@ -914,7 +914,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
const Scope *scope = &(*it);
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::Unknown)
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
debugMessage(scope->classDef, "SymbolDatabase::SymbolDatabase couldn't resolve all user defined types.");
}
}
@ -2919,9 +2919,9 @@ void SymbolDatabase::printOut(const char *title) const
<< type->enclosingScope->className;
}
std::cout << std::endl;
std::cout << " needInitialization: " << (type->needInitialization == Type::Unknown ? "Unknown" :
type->needInitialization == Type::True ? "True" :
type->needInitialization == Type::False ? "False" :
std::cout << " needInitialization: " << (type->needInitialization == Type::NeedInitialization::Unknown ? "Unknown" :
type->needInitialization == Type::NeedInitialization::True ? "True" :
type->needInitialization == Type::NeedInitialization::False ? "False" :
"Invalid") << std::endl;
std::cout << " derivedFrom[" << type->derivedFrom.size() << "] = (";

View File

@ -65,7 +65,7 @@ public:
const Token* classDef; ///< Points to "class" token
const Scope* classScope;
const Scope* enclosingScope;
enum NeedInitialization {
enum class NeedInitialization {
Unknown, True, False
} needInitialization;
@ -106,11 +106,11 @@ public:
classDef(classDef_),
classScope(classScope_),
enclosingScope(enclosingScope_),
needInitialization(Unknown),
needInitialization(NeedInitialization::Unknown),
typeStart(nullptr),
typeEnd(nullptr) {
if (classDef_ && classDef_->str() == "enum")
needInitialization = True;
needInitialization = NeedInitialization::True;
else if (classDef_ && classDef_->str() == "using") {
typeStart = classDef->tokAt(3);
typeEnd = typeStart;

View File

@ -4906,7 +4906,7 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab
const Variable *var = vardecl->variable();
if (!var || var->nameToken() != vardecl)
continue;
if ((!var->isPointer() && var->type() && var->type()->needInitialization != Type::True) ||
if ((!var->isPointer() && var->type() && var->type()->needInitialization != Type::NeedInitialization::True) ||
!var->isLocal() || var->isStatic() || var->isExtern() || var->isReference() || var->isThrow())
continue;