Skip to content

Commit

Permalink
refactor parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhangNV committed Jan 24, 2025
1 parent d7722af commit f690690
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 9 additions & 11 deletions source/slang/slang-check-decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct SemanticsDeclAttributesVisitor : public SemanticsDeclVisitorBase,
bool _searchInitializableMembers(
StructDecl* structDecl,
const DeclVisibility ctorVisibility,
List<KeyValuePair<VarDeclBase*, String>>& resultMembers);
List<VarDeclBase*>& resultMembers);
};

struct SemanticsDeclHeaderVisitor : public SemanticsDeclVisitorBase,
Expand Down Expand Up @@ -12200,7 +12200,7 @@ void SemanticsDeclAttributesVisitor::checkPrimalSubstituteOfAttribute(
bool SemanticsDeclAttributesVisitor::_searchInitializableMembers(
StructDecl* structDecl,
const DeclVisibility ctorVisibility,
List<KeyValuePair<VarDeclBase*, String>>& resultMembers)
List<VarDeclBase*>& resultMembers)
{
auto findMembers = [&](StructDecl* structDecl)
{
Expand All @@ -12217,7 +12217,7 @@ bool SemanticsDeclAttributesVisitor::_searchInitializableMembers(
if (!type.isLeftValue)
continue;

resultMembers.add(KeyValuePair(varDecl, structDecl->getName()->text));
resultMembers.add(varDecl);
structDecl->m_membersVisibleInCtor.add(varDecl);
}
};
Expand All @@ -12244,9 +12244,7 @@ bool SemanticsDeclAttributesVisitor::_searchInitializableMembers(
// Because the parameters in the ctor must have the higher or equal visibility
// than the ctor itself, we don't need to check the visibility level of the
// parameter.
resultMembers.add(KeyValuePair(
as<VarDeclBase>(param),
baseTypeDeclRef.getDecl()->getName()->text));
resultMembers.add(param);
}
}
}
Expand Down Expand Up @@ -12299,7 +12297,7 @@ void SemanticsDeclAttributesVisitor::_synthesizeCtorSignature(StructDecl* struct

// Only the members whose visibility level is higher or equal than the
// constructor's visibility level will appear in the constructor's parameter list.
List<KeyValuePair<VarDeclBase*, String>> resultMembers;
List<VarDeclBase*> resultMembers;
if (!_searchInitializableMembers(structDecl, ctorVisibility, resultMembers))
return;

Expand All @@ -12317,8 +12315,8 @@ void SemanticsDeclAttributesVisitor::_synthesizeCtorSignature(StructDecl* struct
bool stopProcessingDefaultValues = false;
for (SlangInt i = resultMembers.getCount() - 1; i >= 0; i--)
{
auto member = resultMembers[i].key;
auto memberContainerName = resultMembers[i].value;
auto member = resultMembers[i];
auto parentAggDecl = getParentAggTypeDecl(member);;

auto ctorParam = m_astBuilder->create<ParamDecl>();
ctorParam->type = (TypeExp)member->type;
Expand All @@ -12331,9 +12329,9 @@ void SemanticsDeclAttributesVisitor::_synthesizeCtorSignature(StructDecl* struct

ctorParam->parentDecl = ctor;

Name* paramName = (memberContainerName == structDecl->getName()->text)
Name* paramName = (parentAggDecl == structDecl)
? member->getName()
: getName(memberContainerName + "_" + member->getName()->text);
: getName(parentAggDecl->getName()->text + "_" + member->getName()->text);

ctorParam->nameAndLoc = NameLoc(paramName, ctor->loc);

Expand Down
4 changes: 1 addition & 3 deletions tests/language-feature/interfaces/zero-init-interface.slang
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ struct MyType
[numthreads(1, 1, 1)]
void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID)
{
// Note 'MyType' is not a C-Style struct because it has an interface typed member.
// slang will synthesize a constructor for it. __init(IFoo foo)
MyType t = {{}};
MyType t = {};
// BUFFER: 1
outputBuffer[0] = t.foo.method();
}

0 comments on commit f690690

Please sign in to comment.