Skip to content

Commit f02636e

Browse files
committed
Refactoring: Convert enums to enum classes
1 parent d2b9c1f commit f02636e

8 files changed

Lines changed: 28 additions & 28 deletions

lib/astutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ bool isConstVarExpression(const Token *tok);
175175
const Variable *getLHSVariable(const Token *tok);
176176

177177
struct PathAnalysis {
178-
enum Progress {
178+
enum class Progress {
179179
Continue,
180180
Break
181181
};

lib/checkclass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static const char * getFunctionTypeName(Function::Type type)
6969

7070
static bool isVariableCopyNeeded(const Variable &var)
7171
{
72-
return var.isPointer() || (var.type() && var.type()->needInitialization == Type::True) || (var.valueType()->type >= ValueType::Type::CHAR);
72+
return var.isPointer() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True) || (var.valueType()->type >= ValueType::Type::CHAR);
7373
}
7474

7575
//---------------------------------------------------------------------------
@@ -117,7 +117,7 @@ void CheckClass::constructors()
117117
initTok = initTok->linkAt(1);
118118
if (var.isPrivate() && !var.isStatic() && !Token::Match(var.nameToken(), "%varid% ; %varid% =", var.declarationId()) &&
119119
!Token::Match(initTok, "%var%|] {|=") &&
120-
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::True))) {
120+
(!var.isClass() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True))) {
121121
noConstructorError(scope->classDef, scope->className, scope->classDef->str() == "struct");
122122
break;
123123
}
@@ -175,7 +175,7 @@ void CheckClass::constructors()
175175
if (usage[count].assign || usage[count].init || var.isStatic())
176176
continue;
177177

178-
if (var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::False && var.type()->derivedFrom.empty())
178+
if (var.valueType()->pointer == 0 && var.type() && var.type()->needInitialization == Type::NeedInitialization::False && var.type()->derivedFrom.empty())
179179
continue;
180180

181181
if (var.isConst() && func.isOperator()) // We can't set const members in assignment operator
@@ -189,7 +189,7 @@ void CheckClass::constructors()
189189

190190
// Known type that doesn't need initialization or
191191
// known type that has member variables of an unknown type
192-
else if (var.type()->needInitialization != Type::True)
192+
else if (var.type()->needInitialization != Type::NeedInitialization::True)
193193
continue;
194194
}
195195

lib/checkleakautovar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static bool isAutoDealloc(const Variable *var)
6969
/** @todo false negative: check base class for side effects */
7070
/** @todo false negative: check constructors for side effects */
7171
if (var->typeScope() && var->typeScope()->numConstructors == 0 &&
72-
(var->typeScope()->varlist.empty() || var->type()->needInitialization == Type::True) &&
72+
(var->typeScope()->varlist.empty() || var->type()->needInitialization == Type::NeedInitialization::True) &&
7373
var->type()->derivedFrom.empty())
7474
return false;
7575

lib/checkuninitvar.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void CheckUninitVar::check()
9999
void CheckUninitVar::checkScope(const Scope* scope, const std::set<std::string> &arrayTypeDefs)
100100
{
101101
for (const Variable &var : scope->varlist) {
102-
if ((mTokenizer->isCPP() && var.type() && !var.isPointer() && var.type()->needInitialization != Type::True) ||
102+
if ((mTokenizer->isCPP() && var.type() && !var.isPointer() && var.type()->needInitialization != Type::NeedInitialization::True) ||
103103
var.isStatic() || var.isExtern() || var.isReference())
104104
continue;
105105

@@ -197,7 +197,7 @@ void CheckUninitVar::checkStruct(const Token *tok, const Variable &structvar)
197197
if (scope2->className == typeToken->str() && scope2->numConstructors == 0U) {
198198
for (const Variable &var : scope2->varlist) {
199199
if (var.isStatic() || var.hasDefault() || var.isArray() ||
200-
(!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::True)))
200+
(!mTokenizer->isC() && var.isClass() && (!var.type() || var.type()->needInitialization != Type::NeedInitialization::True)))
201201
continue;
202202

203203
// is the variable declared in a inner union?
@@ -693,7 +693,7 @@ bool CheckUninitVar::checkScopeForVariable(const Token *tok, const Variable& var
693693
continue;
694694
}
695695
}
696-
if (var.isPointer() && (var.typeStartToken()->isStandardType() || var.typeStartToken()->isEnumType() || (var.type() && var.type()->needInitialization == Type::True)) && Token::simpleMatch(tok->next(), "= new")) {
696+
if (var.isPointer() && (var.typeStartToken()->isStandardType() || var.typeStartToken()->isEnumType() || (var.type() && var.type()->needInitialization == Type::NeedInitialization::True)) && Token::simpleMatch(tok->next(), "= new")) {
697697
*alloc = CTOR_CALL;
698698

699699
// type has constructor(s)

lib/checkunusedvar.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ bool CheckUnusedVar::isRecordTypeWithoutSideEffects(const Type* type)
13761376
return withoutSideEffects;
13771377

13781378
if (type && type->classScope && type->classScope->numConstructors == 0 &&
1379-
(type->classScope->varlist.empty() || type->needInitialization == Type::True)) {
1379+
(type->classScope->varlist.empty() || type->needInitialization == Type::NeedInitialization::True)) {
13801380
for (std::vector<Type::BaseInfo>::const_iterator i = type->derivedFrom.begin(); i != type->derivedFrom.end(); ++i) {
13811381
if (!isRecordTypeWithoutSideEffects(i->type)) {
13821382
withoutSideEffects=false;

lib/symboldatabase.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
826826
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
827827
Scope *scope = &(*it);
828828
if (scope->definedType)
829-
scope->definedType->needInitialization = Type::True;
829+
scope->definedType->needInitialization = Type::NeedInitialization::True;
830830
}
831831
} else {
832832
// For C++, it is more difficult: Determine if user defined type needs initialization...
@@ -844,7 +844,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
844844
scope->definedType = &mBlankTypes.back();
845845
}
846846

847-
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::Unknown) {
847+
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::NeedInitialization::Unknown) {
848848
// check for default constructor
849849
bool hasDefaultConstructor = false;
850850

@@ -870,7 +870,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
870870
// We assume the default constructor initializes everything.
871871
// Another check will figure out if the constructor actually initializes everything.
872872
if (hasDefaultConstructor)
873-
scope->definedType->needInitialization = Type::False;
873+
scope->definedType->needInitialization = Type::NeedInitialization::False;
874874

875875
// check each member variable to see if it needs initialization
876876
else {
@@ -882,9 +882,9 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
882882
if (var->isClass()) {
883883
if (var->type()) {
884884
// does this type need initialization?
885-
if (var->type()->needInitialization == Type::True)
885+
if (var->type()->needInitialization == Type::NeedInitialization::True)
886886
needInitialization = true;
887-
else if (var->type()->needInitialization == Type::Unknown) {
887+
else if (var->type()->needInitialization == Type::NeedInitialization::Unknown) {
888888
if (!(var->valueType() && var->valueType()->type == ValueType::CONTAINER))
889889
unknown = true;
890890
}
@@ -894,16 +894,16 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
894894
}
895895

896896
if (needInitialization)
897-
scope->definedType->needInitialization = Type::True;
897+
scope->definedType->needInitialization = Type::NeedInitialization::True;
898898
else if (!unknown)
899-
scope->definedType->needInitialization = Type::False;
899+
scope->definedType->needInitialization = Type::NeedInitialization::False;
900900
else {
901-
if (scope->definedType->needInitialization == Type::Unknown)
901+
if (scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
902902
unknowns++;
903903
}
904904
}
905-
} else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::Unknown)
906-
scope->definedType->needInitialization = Type::True;
905+
} else if (scope->type == Scope::eUnion && scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
906+
scope->definedType->needInitialization = Type::NeedInitialization::True;
907907
}
908908

909909
retry++;
@@ -914,7 +914,7 @@ void SymbolDatabase::createSymbolDatabaseNeedInitialization()
914914
for (std::list<Scope>::iterator it = scopeList.begin(); it != scopeList.end(); ++it) {
915915
const Scope *scope = &(*it);
916916

917-
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::Unknown)
917+
if (scope->isClassOrStruct() && scope->definedType->needInitialization == Type::NeedInitialization::Unknown)
918918
debugMessage(scope->classDef, "SymbolDatabase::SymbolDatabase couldn't resolve all user defined types.");
919919
}
920920
}
@@ -2919,9 +2919,9 @@ void SymbolDatabase::printOut(const char *title) const
29192919
<< type->enclosingScope->className;
29202920
}
29212921
std::cout << std::endl;
2922-
std::cout << " needInitialization: " << (type->needInitialization == Type::Unknown ? "Unknown" :
2923-
type->needInitialization == Type::True ? "True" :
2924-
type->needInitialization == Type::False ? "False" :
2922+
std::cout << " needInitialization: " << (type->needInitialization == Type::NeedInitialization::Unknown ? "Unknown" :
2923+
type->needInitialization == Type::NeedInitialization::True ? "True" :
2924+
type->needInitialization == Type::NeedInitialization::False ? "False" :
29252925
"Invalid") << std::endl;
29262926

29272927
std::cout << " derivedFrom[" << type->derivedFrom.size() << "] = (";

lib/symboldatabase.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CPPCHECKLIB Type {
6565
const Token* classDef; ///< Points to "class" token
6666
const Scope* classScope;
6767
const Scope* enclosingScope;
68-
enum NeedInitialization {
68+
enum class NeedInitialization {
6969
Unknown, True, False
7070
} needInitialization;
7171

@@ -106,11 +106,11 @@ class CPPCHECKLIB Type {
106106
classDef(classDef_),
107107
classScope(classScope_),
108108
enclosingScope(enclosingScope_),
109-
needInitialization(Unknown),
109+
needInitialization(NeedInitialization::Unknown),
110110
typeStart(nullptr),
111111
typeEnd(nullptr) {
112112
if (classDef_ && classDef_->str() == "enum")
113-
needInitialization = True;
113+
needInitialization = NeedInitialization::True;
114114
else if (classDef_ && classDef_->str() == "using") {
115115
typeStart = classDef->tokAt(3);
116116
typeEnd = typeStart;

lib/valueflow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4906,7 +4906,7 @@ static void valueFlowUninit(TokenList *tokenlist, SymbolDatabase * /*symbolDatab
49064906
const Variable *var = vardecl->variable();
49074907
if (!var || var->nameToken() != vardecl)
49084908
continue;
4909-
if ((!var->isPointer() && var->type() && var->type()->needInitialization != Type::True) ||
4909+
if ((!var->isPointer() && var->type() && var->type()->needInitialization != Type::NeedInitialization::True) ||
49104910
!var->isLocal() || var->isStatic() || var->isExtern() || var->isReference() || var->isThrow())
49114911
continue;
49124912

0 commit comments

Comments
 (0)