From f690690aae9f45902dde821c19769f3af7a46ea5 Mon Sep 17 00:00:00 2001 From: kaizhangNV Date: Thu, 23 Jan 2025 18:59:23 -0800 Subject: [PATCH] refactor parameter name --- source/slang/slang-check-decl.cpp | 20 +++++++++---------- .../interfaces/zero-init-interface.slang | 4 +--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 890a5d1fb4..abe3a3d9c0 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -107,7 +107,7 @@ struct SemanticsDeclAttributesVisitor : public SemanticsDeclVisitorBase, bool _searchInitializableMembers( StructDecl* structDecl, const DeclVisibility ctorVisibility, - List>& resultMembers); + List& resultMembers); }; struct SemanticsDeclHeaderVisitor : public SemanticsDeclVisitorBase, @@ -12200,7 +12200,7 @@ void SemanticsDeclAttributesVisitor::checkPrimalSubstituteOfAttribute( bool SemanticsDeclAttributesVisitor::_searchInitializableMembers( StructDecl* structDecl, const DeclVisibility ctorVisibility, - List>& resultMembers) + List& resultMembers) { auto findMembers = [&](StructDecl* structDecl) { @@ -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); } }; @@ -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(param), - baseTypeDeclRef.getDecl()->getName()->text)); + resultMembers.add(param); } } } @@ -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> resultMembers; + List resultMembers; if (!_searchInitializableMembers(structDecl, ctorVisibility, resultMembers)) return; @@ -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(); ctorParam->type = (TypeExp)member->type; @@ -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); diff --git a/tests/language-feature/interfaces/zero-init-interface.slang b/tests/language-feature/interfaces/zero-init-interface.slang index 45abe8afec..ed3b1eaa44 100644 --- a/tests/language-feature/interfaces/zero-init-interface.slang +++ b/tests/language-feature/interfaces/zero-init-interface.slang @@ -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(); }