diff --git a/sources/ClangSharp.Interop/clangsharp/clangsharp.cs b/sources/ClangSharp.Interop/clangsharp/clangsharp.cs index 1c675a8e..e2ad41ab 100644 --- a/sources/ClangSharp.Interop/clangsharp/clangsharp.cs +++ b/sources/ClangSharp.Interop/clangsharp/clangsharp.cs @@ -1032,6 +1032,9 @@ public static partial class @clangsharp [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOriginalType", ExactSpelling = true)] public static extern CXType Type_getOriginalType(CXType CT); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl", ExactSpelling = true)] + public static extern CXCursor Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT); + [DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOwnedTagDecl", ExactSpelling = true)] public static extern CXCursor Type_getOwnedTagDecl(CXType CT); diff --git a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs index 517d387b..d09e2a5c 100644 --- a/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs +++ b/sources/ClangSharp/Types/SubstTemplateTypeParmType.cs @@ -9,14 +9,21 @@ namespace ClangSharp; public sealed class SubstTemplateTypeParmType : Type { + private readonly Lazy _associatedDecl; private readonly Lazy _replacedParameter; internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_SubstTemplateTypeParm) { + _associatedDecl = new Lazy(() => { + CXCursor cursor = clangsharp.Type_getSubstTemplateTypeParamAssociatedDecl(Handle); + return cursor.IsNull ? null : TranslationUnit.GetOrCreate(cursor); + }); _replacedParameter = new Lazy(() => TranslationUnit.GetOrCreate(Handle.OriginalType)); } public TemplateTypeParmType ReplacedParameter => _replacedParameter.Value; public Type ReplacementType => Desugar; + + public Decl? AssociatedDecl => _associatedDecl.Value; } diff --git a/sources/libClangSharp/ClangSharp.cpp b/sources/libClangSharp/ClangSharp.cpp index 02c76f2d..db92c86a 100644 --- a/sources/libClangSharp/ClangSharp.cpp +++ b/sources/libClangSharp/ClangSharp.cpp @@ -5366,6 +5366,17 @@ CXType clangsharp_Type_getOriginalType(CXType CT) { return MakeCXType(QualType(), GetTypeTU(CT)); } +CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT) { + QualType T = GetQualType(CT); + const Type* TP = T.getTypePtrOrNull(); + + if (const SubstTemplateTypeParmType* STTPT = dyn_cast(TP)) { + return MakeCXCursor(STTPT->getAssociatedDecl(), GetTypeTU(CT)); + } + + clang_getNullCursor(); +} + CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT) { QualType T = GetQualType(CT); const Type* TP = T.getTypePtrOrNull(); diff --git a/sources/libClangSharp/ClangSharp.h b/sources/libClangSharp/ClangSharp.h index a79013e7..f5156131 100644 --- a/sources/libClangSharp/ClangSharp.h +++ b/sources/libClangSharp/ClangSharp.h @@ -817,6 +817,8 @@ CLANGSHARP_LINKAGE int clangsharp_Type_getNumRows(CXType CT); CLANGSHARP_LINKAGE CXType clangsharp_Type_getOriginalType(CXType CT); +CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT); + CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT); CLANGSHARP_LINKAGE CXType clangsharp_Type_getPointeeType(CXType CT);