Skip to content

Commit

Permalink
refactor _getDefaultCtor
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhangNV committed Sep 19, 2024
1 parent 5401494 commit 39268d6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8299,7 +8299,6 @@ namespace Slang
return ctor->containsOption(ConstructorTags::Synthesized)
&& ctor->getParameters().getCount() != 0
&& !allParamHaveInitExpr(ctor);
// return ctor->findModifier<SynthesizedModifier>();
}

template<typename T>
Expand Down
19 changes: 14 additions & 5 deletions source/slang/slang-constructor-utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,24 @@ namespace Slang
return true;
}

static inline bool _isDefaultCtor(ConstructorDecl* ctor)
{
// 1. default ctor must have definition
// 2. either 2.1 or 2.2 is safisfied
// 2.1. default ctor must have no parameters
// 2.2. default ctor can have parameters, but all parameters have init expr (Because we won't differentiate this case from 2.)
if (!ctor->body || (ctor->members.getCount() != 0 && !allParamHaveInitExpr(ctor)))
return false;

return true;
}

ConstructorDecl* _getDefaultCtor(StructDecl* structDecl)
{
for (auto ctor : structDecl->getMembersOfType<ConstructorDecl>())
{
// 1. default ctor must have definition
// 2. default ctor must have no parameters or all parameters have init expr
if (!ctor->body || (ctor->members.getCount() != 0 && !allParamHaveInitExpr(ctor)))
continue;
return ctor;
if (_isDefaultCtor(ctor))
return ctor;
}
return nullptr;
}
Expand Down

0 comments on commit 39268d6

Please sign in to comment.