Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AssociatedDecl property to SubstTemplateTypeParamType. #529

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sources/ClangSharp.Interop/clangsharp/clangsharp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions sources/ClangSharp/Types/SubstTemplateTypeParmType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ namespace ClangSharp;

public sealed class SubstTemplateTypeParmType : Type
{
private readonly Lazy<Decl?> _associatedDecl;
private readonly Lazy<TemplateTypeParmType> _replacedParameter;

internal SubstTemplateTypeParmType(CXType handle) : base(handle, CXType_Unexposed, CX_TypeClass_SubstTemplateTypeParm)
{
_associatedDecl = new Lazy<Decl?>(() => {
CXCursor cursor = clangsharp.Type_getSubstTemplateTypeParamAssociatedDecl(Handle);
return cursor.IsNull ? null : TranslationUnit.GetOrCreate<Decl>(cursor);
});
_replacedParameter = new Lazy<TemplateTypeParmType>(() => TranslationUnit.GetOrCreate<TemplateTypeParmType>(Handle.OriginalType));
}

public TemplateTypeParmType ReplacedParameter => _replacedParameter.Value;

public Type ReplacementType => Desugar;

public Decl? AssociatedDecl => _associatedDecl.Value;
}
11 changes: 11 additions & 0 deletions sources/libClangSharp/ClangSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SubstTemplateTypeParmType>(TP)) {
return MakeCXCursor(STTPT->getAssociatedDecl(), GetTypeTU(CT));
}

clang_getNullCursor();
}

CXCursor clangsharp_Type_getOwnedTagDecl(CXType CT) {
QualType T = GetQualType(CT);
const Type* TP = T.getTypePtrOrNull();
Expand Down
2 changes: 2 additions & 0 deletions sources/libClangSharp/ClangSharp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down