summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorHarsh Aggarwal (NVIDIA) <haaggarwal@nvidia.com>2025-04-24 10:11:30 +0530
committerGitHub <noreply@github.com>2025-04-24 04:41:30 +0000
commitb78a8ba006fc9253cd1fd88fb7dd1eacfa749dfa (patch)
treef82da8185be49dff6791306b6466155d20ca6fb8 /source
parent785669c8771c01d57914ec0075315e8ae61b6a31 (diff)
Fix #6544: Properly format nested type names in extensions (#6769)
* Fix #6544: Properly format nested type names in extensions Modify DeclRefBase::toText to properly handle types defined in extensions by qualifying them with their parent type name. This ensures getFullName() returns the full name like 'FullPrecisionOptimizer<half>.State' instead of just '.State'. Also handle other nested types in structs/classes similarly. * Update extension reflection handling - with generics args and namespaces - stopping namespace inclusion for extension members - Update to use getTargetType() to handle the generic arguments - update test cases * Simplify code to remove using parentDecl
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ast-decl-ref.cpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/source/slang/slang-ast-decl-ref.cpp b/source/slang/slang-ast-decl-ref.cpp
index a44e5b817..1881f1b3c 100644
--- a/source/slang/slang-ast-decl-ref.cpp
+++ b/source/slang/slang-ast-decl-ref.cpp
@@ -334,29 +334,39 @@ void DeclRefBase::toText(StringBuilder& out)
SubstitutionSet substSet(this);
- List<Decl*> decls;
- for (auto dd = getDecl(); dd; dd = dd->parentDecl)
+ // Build a list of parent DeclRefs instead of just Decls
+ List<DeclRefBase*> declRefs;
+
+ for (DeclRefBase* dr = this; dr; dr = dr->getParent())
{
+ auto dd = dr->getDecl();
+
+ // If this declaration is an extension, add it and then stop gathering parents
+ if (as<ExtensionDecl>(dd))
+ {
+ declRefs.add(dr);
+ break; // Stop gathering parent DeclRefs to exclude namespace
+ }
+
// Skip the module, file & include decls since their names are
// considered "transparent"
- //
if (as<ModuleDecl>(dd) || as<FileDecl>(dd) || as<IncludeDecl>(dd))
continue;
// Skip base decls in generic containers. We will handle them when we handle the generic
// decl.
- //
if (dd->parentDecl && as<GenericDecl>(dd->parentDecl))
continue;
- decls.add(dd);
+ declRefs.add(dr);
}
- decls.reverse();
+ declRefs.reverse();
bool first = true;
- for (auto decl : decls)
+ for (auto declRef : declRefs)
{
+ auto decl = declRef->getDecl();
if (!first)
out << ".";
first = false;
@@ -387,8 +397,13 @@ void DeclRefBase::toText(StringBuilder& out)
out << ">";
}
}
-
- // TODO: What do we do about extensions?
+ }
+ else if (auto extDecl = as<ExtensionDecl>(decl))
+ {
+ if (extDecl->targetType)
+ {
+ getTargetType(getCurrentASTBuilder(), getParent())->toText(out);
+ }
}
}
}