CheckClass: Fix endless recursion
This commit is contained in:
parent
7658aa86bd
commit
205af353db
|
@ -137,8 +137,7 @@ void CheckClass::constructors()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<Usage> usageList;
|
std::vector<Usage> usageList = createUsageList(scope);
|
||||||
createUsageList(usageList, scope);
|
|
||||||
|
|
||||||
for (const Function &func : scope->functionList) {
|
for (const Function &func : scope->functionList) {
|
||||||
if (!func.hasBody() || !(func.isConstructor() || func.type == Function::eOperatorEqual))
|
if (!func.hasBody() || !(func.isConstructor() || func.type == Function::eOperatorEqual))
|
||||||
|
@ -535,19 +534,33 @@ bool CheckClass::canNotMove(const Scope *scope)
|
||||||
return constructor && !(publicAssign || publicCopy || publicMove);
|
return constructor && !(publicAssign || publicCopy || publicMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckClass::createUsageList(std::vector<Usage>& usageList, const Scope *scope)
|
static void getAllVariableMembers(const Scope *scope, std::vector<const Variable *>& varList, std::vector<const Scope *> &baseClasses)
|
||||||
{
|
{
|
||||||
|
if (std::find(baseClasses.begin(), baseClasses.end(), scope) != baseClasses.end())
|
||||||
|
return;
|
||||||
|
baseClasses.push_back(scope);
|
||||||
for (const Variable& var: scope->varlist)
|
for (const Variable& var: scope->varlist)
|
||||||
usageList.push_back(Usage(&var));
|
varList.push_back(&var);
|
||||||
if (scope->definedType) {
|
if (scope->definedType) {
|
||||||
for (const Type::BaseInfo& baseInfo: scope->definedType->derivedFrom) {
|
for (const Type::BaseInfo& baseInfo: scope->definedType->derivedFrom) {
|
||||||
const Scope *baseClass = baseInfo.type ? baseInfo.type->classScope : nullptr;
|
const Scope *baseClass = baseInfo.type ? baseInfo.type->classScope : nullptr;
|
||||||
if (baseClass && baseClass->isClassOrStruct() && baseClass->numConstructors == 0)
|
if (baseClass && baseClass->isClassOrStruct() && baseClass->numConstructors == 0)
|
||||||
createUsageList(usageList, baseClass);
|
getAllVariableMembers(baseClass, varList, baseClasses);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<CheckClass::Usage> CheckClass::createUsageList(const Scope *scope)
|
||||||
|
{
|
||||||
|
std::vector<Usage> ret;
|
||||||
|
std::vector<const Variable *> varlist;
|
||||||
|
std::vector<const Scope *> temp;
|
||||||
|
getAllVariableMembers(scope, varlist, temp);
|
||||||
|
for (const Variable *var: varlist)
|
||||||
|
ret.emplace_back(var);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void CheckClass::assignVar(std::vector<Usage> &usageList, nonneg int varid)
|
void CheckClass::assignVar(std::vector<Usage> &usageList, nonneg int varid)
|
||||||
{
|
{
|
||||||
for (Usage& usage: usageList) {
|
for (Usage& usage: usageList) {
|
||||||
|
|
|
@ -296,10 +296,9 @@ private:
|
||||||
/**
|
/**
|
||||||
* @brief Create usage list that contains all scope members and also members
|
* @brief Create usage list that contains all scope members and also members
|
||||||
* of base classes without constructors.
|
* of base classes without constructors.
|
||||||
* @param usageList usageList that will be filled up
|
|
||||||
* @param scope current class scope
|
* @param scope current class scope
|
||||||
*/
|
*/
|
||||||
static void createUsageList(std::vector<Usage>& usageList, const Scope *scope);
|
static std::vector<Usage> createUsageList(const Scope *scope);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief assign a variable in the varlist
|
* @brief assign a variable in the varlist
|
||||||
|
|
Loading…
Reference in New Issue