Skip to content

Commit 5b4f845

Browse files
committed
Add AssociatedDecl property to SubstTemplateTypeParamType.
* This calls getAssociatedDecl() on the underlying clang c++ type object. * Note: I added a function was added to clangsharp.cpp and .h, but the clangsharp.cs file was updated manually. I was having issues getting ClangSharpPInvokeGenerator output the .cs source files correctly.
1 parent b9479d2 commit 5b4f845

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

sources/ClangSharp.Interop/clangsharp/clangsharp.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,9 @@ public static partial class @clangsharp
10321032
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOriginalType", ExactSpelling = true)]
10331033
public static extern CXType Type_getOriginalType(CXType CT);
10341034

1035+
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl", ExactSpelling = true)]
1036+
public static extern CXCursor Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT);
1037+
10351038
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOwnedTagDecl", ExactSpelling = true)]
10361039
public static extern CXCursor Type_getOwnedTagDecl(CXType CT);
10371040

sources/ClangSharp/Types/SubstTemplateTypeParmType.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ namespace ClangSharp;
99

1010
public sealed class SubstTemplateTypeParmType : Type
1111
{
12+
private readonly Lazy<Decl?> _associatedDecl;
1213
private readonly Lazy<TemplateTypeParmType> _replacedParameter;
1314

1415
internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_SubstTemplateTypeParm)
1516
{
17+
_associatedDecl = new Lazy<Decl?>(() => {
18+
CXCursor cursor = clangsharp.Type_getSubstTemplateTypeParamAssociatedDecl(Handle);
19+
return cursor.IsNull ? null : TranslationUnit.GetOrCreate<Decl>(cursor);
20+
});
1621
_replacedParameter = new Lazy<TemplateTypeParmType>(() => TranslationUnit.GetOrCreate<TemplateTypeParmType>(Handle.OriginalType));
1722
}
1823

1924
public TemplateTypeParmType ReplacedParameter => _replacedParameter.Value;
2025

2126
public Type ReplacementType => Desugar;
27+
28+
public Decl? AssociatedDecl => _associatedDecl.Value;
2229
}

sources/libClangSharp/ClangSharp.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5366,6 +5366,17 @@ CXType clangsharp_Type_getOriginalType(CXType CT) {
53665366
return MakeCXType(QualType(), GetTypeTU(CT));
53675367
}
53685368

5369+
CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT) {
5370+
QualType T = GetQualType(CT);
5371+
const Type* TP = T.getTypePtrOrNull();
5372+
5373+
if (const SubstTemplateTypeParmType* STTPT = dyn_cast<SubstTemplateTypeParmType>(TP)) {
5374+
return MakeCXCursor(STTPT->getAssociatedDecl(), GetTypeTU(CT));
5375+
}
5376+
5377+
clang_getNullCursor();
5378+
}
5379+
53695380
CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT) {
53705381
QualType T = GetQualType(CT);
53715382
const Type* TP = T.getTypePtrOrNull();

sources/libClangSharp/ClangSharp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,8 @@ CLANGSHARP_LINKAGE int clangsharp_Type_getNumRows(CXType CT);
817817

818818
CLANGSHARP_LINKAGE CXType clangsharp_Type_getOriginalType(CXType CT);
819819

820+
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT);
821+
820822
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT);
821823

822824
CLANGSHARP_LINKAGE CXType clangsharp_Type_getPointeeType(CXType CT);

0 commit comments

Comments
 (0)