diff options
| author | Xuanda Yang <th3charlie@gmail.com> | 2025-09-10 15:55:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-10 22:55:00 +0000 |
| commit | f3e26754c4b63fee419407752b771ecf0bb8ed5a (patch) | |
| tree | 15188e3e51b77e6027bba9d49c071c3d426012a9 | |
| parent | c5607e9d68e9082ada9441f1949937f6b16d5c7f (diff) | |
Add FindModifier for Declarations (#8308)
Add `findModifier` for `DeclReflection` so pattern like `extern struct
foo;` can be properly reflected.
Closes #8009
| -rw-r--r-- | include/slang-deprecated.h | 3 | ||||
| -rw-r--r-- | include/slang.h | 7 | ||||
| -rw-r--r-- | source/slang/slang-reflection-api.cpp | 15 |
3 files changed, 25 insertions, 0 deletions
diff --git a/include/slang-deprecated.h b/include/slang-deprecated.h index c81ae8537..026845888 100644 --- a/include/slang-deprecated.h +++ b/include/slang-deprecated.h @@ -750,6 +750,9 @@ extern "C" SLANG_API SlangReflectionGeneric* spReflectionDecl_castToGeneric(SlangReflectionDecl* decl); SLANG_API SlangReflectionType* spReflection_getTypeFromDecl(SlangReflectionDecl* decl); SLANG_API SlangReflectionDecl* spReflectionDecl_getParent(SlangReflectionDecl* decl); + SLANG_API SlangReflectionModifier* spReflectionDecl_findModifier( + SlangReflectionDecl* decl, + SlangModifierID modifierID); // Generic Reflection diff --git a/include/slang.h b/include/slang.h index a3d979de5..a3ed2112a 100644 --- a/include/slang.h +++ b/include/slang.h @@ -3518,6 +3518,13 @@ struct DeclReflection return (DeclReflection*)spReflectionDecl_getParent((SlangReflectionDecl*)this); } + Modifier* findModifier(Modifier::ID id) + { + return (Modifier*)spReflectionDecl_findModifier( + (SlangReflectionDecl*)this, + (SlangModifierID)id); + } + template<Kind K> struct FilteredList { diff --git a/source/slang/slang-reflection-api.cpp b/source/slang/slang-reflection-api.cpp index c5d39859e..a14bb4ac1 100644 --- a/source/slang/slang-reflection-api.cpp +++ b/source/slang/slang-reflection-api.cpp @@ -3516,6 +3516,21 @@ SLANG_API SlangReflectionModifier* spReflectionFunction_FindModifier( return spReflectionVariable_FindModifier(varRefl, modifierID); } +SLANG_API SlangReflectionModifier* spReflectionDecl_findModifier( + SlangReflectionDecl* decl, + SlangModifierID modifierID) +{ + Decl* slangDecl = (Decl*)decl; + if (!slangDecl) + return nullptr; + + auto varRefl = convert(DeclRef<Decl>(slangDecl)); + if (!varRefl) + return nullptr; + + return spReflectionVariable_FindModifier(varRefl, modifierID); +} + SLANG_API unsigned int spReflectionFunction_GetUserAttributeCount(SlangReflectionFunction* inFunc) { auto func = convertToFunc(inFunc); |
