Refactoring: Convert enums to enum classes
This commit is contained in:
parent
d2b9c1f15a
commit
f02636e995
|
@ -175,7 +175,7 @@ bool isConstVarExpression(const Token *tok);
|
||||||
const Variable *getLHSVariable(const Token *tok);
|
const Variable *getLHSVariable(const Token *tok);
|
||||||
|
|
||||||
struct PathAnalysis {
|
struct PathAnalysis {
|
||||||
enum Progress {
|
enum class Progress {
|
||||||
Continue,
|
Continue,
|
||||||
Break
|
Break
|
||||||
};
|
};
|
||||||
|
|
|
@ -69,7 +69,7 @@ static const char * getFunctionTypeName(Function::Type type)
|
||||||
|
|
||||||
static bool isVariableCopyNeeded(const Variable &var)
|
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);
|
initTok = initTok->linkAt(1);
|
||||||
if (var.isPrivate() && !var.isStatic() && !Token::Match(var.nameToken(), "%varid% ; %varid% =", var.declarationId()) &&
|
if (var.isPrivate() && !var.isStatic() && !Token::Match(var.nameToken(), "%varid% ; %varid% =", var.declarationId()) &&
|
||||||
!Token::Match(initTok, "%var%|] {|=") &&
|
!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");
|
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ void CheckClass::constructors()
|
||||||
if (usage[count].assign || usage[count].init || var.isStatic())
|
if (usage[count].assign || usage[count].init || var.isStatic())
|
||||||
continue;
|
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;
|
continue;
|
||||||
|
|
||||||
if (var.isConst() && func.isOperator()) // We can't set const members in assignment operator
|
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 doesn't need initialization or
|
||||||
// known type that has member variables of an unknown type
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ static bool isAutoDealloc(const Variable *var)
|
||||||
/** @todo false negative: check base class for side effects */
|
/** @todo false negative: check base class for side effects */
|
||||||
/** @todo false negative: check constructors for side effects */
|
/** @todo false negative: check constructors for side effects */
|
||||||
if (var->typeScope() && var->typeScope()->numConstructors == 0 &&
|
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())
|
var->type()->derivedFrom.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ void CheckUninitVar::check()
|
||||||
void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDefs)
|
void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDefs)
|
||||||
{
|
{
|
||||||
for (const Variable &var : scope->varlist) {
|
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())
|
var.isStatic() || var.isExtern() || var.isReference())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar)
|
||||||
if (scope2->className == typeToken->str() && scope2->numConstructors == 0U) {
|
if (scope2->className == typeToken->str() && scope2->numConstructors == 0U) {
|
||||||
for (const Variable &var : scope2->varlist) {
|
for (const Variable &var : scope2->varlist) {
|
||||||
if (var.isStatic() || var.hasDefault() || var.isArray() ||
|
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;
|
continue;
|
||||||
|
|
||||||
// is the variable declared in a inner union?
|
// is the variable declared in a inner union?
|
||||||
|
@ -693,7 +693,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
|
||||||
continue;
|
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;
|
*alloc = CTOR_CALL;
|
||||||
|
|
||||||
// type has constructor(s)
|
// type has constructor(s)
|
||||||
|
|
|
@ -1376,7 +1376,7 @@ bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type)
|
||||||
return withoutSideEffects;
|
return withoutSideEffects;
|
||||||
|
|
||||||
if (type && type->classScope && type->classScope->numConstructors == 0 &&
|
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) {
|
for (std::vector<Type::BaseInfo>::const_iterator i = type->derivedFrom.begin(); i != type->derivedFrom.end(); ++i) {
|
||||||
if (!isRecordTypeWithoutSideEffects(i->type)) {
|
if (!isRecordTypeWithoutSideEffects(i->type)) {
|
||||||
withoutSideEffects=false;
|
withoutSideEffects=false;
|
||||||
|
|
|
@ -826,7 +826,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
|
||||||
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
|
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
|
||||||
Scope *scope = &(*it);
|
Scope *scope = &(*it);
|
||||||
if (scope->definedType)
|
if (scope->definedType)
|
||||||
scope->definedType->needInitialization = Type::True;
|
scope->definedType->needInitialization = Type::NeedInitialization::True;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// For C++, it is more difficult: Determine if user defined type needs initialization...
|
// For C++, it is more difficult: Determine if user defined type needs initialization...
|
||||||
|
@ -844,7 +844,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
|
||||||
scope->definedType = &mBlankTypes.back();
|
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
|
// check for default constructor
|
||||||
bool hasDefaultConstructor = false;
|
bool hasDefaultConstructor = false;
|
||||||
|
|
||||||
|
@ -870,7 +870,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
|
||||||
// We assume the default constructor initializes everything.
|
// We assume the default constructor initializes everything.
|
||||||
// Another check will figure out if the constructor actually initializes everything.
|
// Another check will figure out if the constructor actually initializes everything.
|
||||||
if (hasDefaultConstructor)
|
if (hasDefaultConstructor)
|
||||||
scope->definedType->needInitialization = Type::False;
|
scope->definedType->needInitialization = Type::NeedInitialization::False;
|
||||||
|
|
||||||
// check each member variable to see if it needs initialization
|
// check each member variable to see if it needs initialization
|
||||||
else {
|
else {
|
||||||
|
@ -882,9 +882,9 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
|
||||||
if (var->isClass()) {
|
if (var->isClass()) {
|
||||||
if (var->type()) {
|
if (var->type()) {
|
||||||
// does this type need initialization?
|
// does this type need initialization?
|
||||||
if (var->type()->needInitialization == Type::True)
|
if (var->type()->needInitialization == Type::NeedInitialization::True)
|
||||||
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))
|
if (!(var->valueType() && var->valueType()->type == ValueType::CONTAINER))
|
||||||
unknown = true;
|
unknown = true;
|
||||||
}
|
}
|
||||||
|
@ -894,16 +894,16 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needInitialization)
|
if (needInitialization)
|
||||||
scope->definedType->needInitialization = Type::True;
|
scope->definedType->needInitialization = Type::NeedInitialization::True;
|
||||||
else if (!unknown)
|
else if (!unknown)
|
||||||
scope->definedType->needInitialization = Type::False;
|
scope->definedType->needInitialization = Type::NeedInitialization::False;
|
||||||
else {
|
else {
|
||||||
if (scope->definedType->needInitialization == Type::Unknown)
|
if (scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
|
||||||
unknowns++;
|
unknowns++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::Unknown)
|
} else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
|
||||||
scope->definedType->needInitialization = Type::True;
|
scope->definedType->needInitialization = Type::NeedInitialization::True;
|
||||||
}
|
}
|
||||||
|
|
||||||
retry++;
|
retry++;
|
||||||
|
@ -914,7 +914,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
|
||||||
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
|
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
|
||||||
const Scope *scope = &(*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.");
|
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;
|
<< type->enclosingScope->className;
|
||||||
}
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
std::cout << " needInitialization: " << (type->needInitialization == Type::Unknown ? "Unknown" :
|
std::cout << " needInitialization: " << (type->needInitialization == Type::NeedInitialization::Unknown ? "Unknown" :
|
||||||
type->needInitialization == Type::True ? "True" :
|
type->needInitialization == Type::NeedInitialization::True ? "True" :
|
||||||
type->needInitialization == Type::False ? "False" :
|
type->needInitialization == Type::NeedInitialization::False ? "False" :
|
||||||
"Invalid") << std::endl;
|
"Invalid") << std::endl;
|
||||||
|
|
||||||
std::cout << " derivedFrom[" << type->derivedFrom.size() << "] = (";
|
std::cout << " derivedFrom[" << type->derivedFrom.size() << "] = (";
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
const Token* classDef; ///< Points to "class" token
|
const Token* classDef; ///< Points to "class" token
|
||||||
const Scope* classScope;
|
const Scope* classScope;
|
||||||
const Scope* enclosingScope;
|
const Scope* enclosingScope;
|
||||||
enum NeedInitialization {
|
enum class NeedInitialization {
|
||||||
Unknown, True, False
|
Unknown, True, False
|
||||||
} needInitialization;
|
} needInitialization;
|
||||||
|
|
||||||
|
@ -106,11 +106,11 @@ public:
|
||||||
classDef(classDef_),
|
classDef(classDef_),
|
||||||
classScope(classScope_),
|
classScope(classScope_),
|
||||||
enclosingScope(enclosingScope_),
|
enclosingScope(enclosingScope_),
|
||||||
needInitialization(Unknown),
|
needInitialization(NeedInitialization::Unknown),
|
||||||
typeStart(nullptr),
|
typeStart(nullptr),
|
||||||
typeEnd(nullptr) {
|
typeEnd(nullptr) {
|
||||||
if (classDef_ && classDef_->str() == "enum")
|
if (classDef_ && classDef_->str() == "enum")
|
||||||
needInitialization = True;
|
needInitialization = NeedInitialization::True;
|
||||||
else if (classDef_ && classDef_->str() == "using") {
|
else if (classDef_ && classDef_->str() == "using") {
|
||||||
typeStart = classDef->tokAt(3);
|
typeStart = classDef->tokAt(3);
|
||||||
typeEnd = typeStart;
|
typeEnd = typeStart;
|
||||||
|
|
|
@ -4906,7 +4906,7 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab
|
||||||
const Variable *var = vardecl->variable();
|
const Variable *var = vardecl->variable();
|
||||||
if (!var || var->nameToken() != vardecl)
|
if (!var || var->nameToken() != vardecl)
|
||||||
continue;
|
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())
|
!var->isLocal() || var->isStatic() || var->isExtern() || var->isReference() || var->isThrow())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue