Skip to content

Commit fef1919

Browse files
Merge pull request #529 from ceresgalax/feature_sttpt_associated_decl
Add AssociatedDecl property to SubstTemplateTypeParamType.
2 parents 0296dbf + 5b4f845 commit fef1919

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
@@ -1043,6 +1043,9 @@ public static partial class @clangsharp
10431043
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOriginalType", ExactSpelling = true)]
10441044
public static extern CXType Type_getOriginalType(CXType CT);
10451045

1046+
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl", ExactSpelling = true)]
1047+
public static extern CXCursor Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT);
1048+
10461049
[DllImport("libClangSharp", CallingConvention = CallingConvention.Cdecl, EntryPoint = "clangsharp_Type_getOwnedTagDecl", ExactSpelling = true)]
10471050
public static extern CXCursor Type_getOwnedTagDecl(CXType CT);
10481051

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
@@ -5401,6 +5401,17 @@ CXType clangsharp_Type_getOriginalType(CXType CT) {
54015401
return MakeCXType(QualType(), GetTypeTU(CT));
54025402
}
54035403

5404+
CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT) {
5405+
QualType T = GetQualType(CT);
5406+
const Type* TP = T.getTypePtrOrNull();
5407+
5408+
if (const SubstTemplateTypeParmType* STTPT = dyn_cast<SubstTemplateTypeParmType>(TP)) {
5409+
return MakeCXCursor(STTPT->getAssociatedDecl(), GetTypeTU(CT));
5410+
}
5411+
5412+
clang_getNullCursor();
5413+
}
5414+
54045415
CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT) {
54055416
QualType T = GetQualType(CT);
54065417
const Type* TP = T.getTypePtrOrNull();

sources/libClangSharp/ClangSharp.h

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

842842
CLANGSHARP_LINKAGE CXType clangsharp_Type_getOriginalType(CXType CT);
843843

844+
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getSubstTemplateTypeParamAssociatedDecl(CXType CT);
845+
844846
CLANGSHARP_LINKAGE CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT);
845847

846848
CLANGSHARP_LINKAGE CXType clangsharp_Type_getPointeeType(CXType CT);

0 commit comments

Comments
 (0)