Skip to content
Merged
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
14 changes: 11 additions & 3 deletions sources/ClangSharp/Cursors/Decls/Decl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Decl : Cursor
private readonly Lazy<Stmt?> _body;
private readonly Lazy<Decl> _canonicalDecl;
private readonly Lazy<IReadOnlyList<Decl>> _decls;
private readonly Lazy<TemplateDecl> _describedTemplate;
private readonly Lazy<TemplateDecl?> _describedTemplate;
private readonly Lazy<Decl> _mostRecentDecl;
private readonly Lazy<Decl> _nextDeclInContext;
private readonly Lazy<Decl> _nonClosureContext;
Expand Down Expand Up @@ -62,7 +62,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl
return decls;
});
;
_describedTemplate = new Lazy<TemplateDecl>(() => TranslationUnit.GetOrCreate<TemplateDecl>(Handle.DescribedTemplate));
_describedTemplate = new Lazy<TemplateDecl?>(() =>
{
CXCursor describedTemplate = Handle.DescribedTemplate;
return describedTemplate.IsNull ? null : TranslationUnit.GetOrCreate<TemplateDecl>(describedTemplate);
});
_mostRecentDecl = new Lazy<Decl>(() => TranslationUnit.GetOrCreate<Decl>(Handle.MostRecentDecl));
_nextDeclInContext = new Lazy<Decl>(() => TranslationUnit.GetOrCreate<Decl>(Handle.NextDeclInContext));
_nonClosureContext = new Lazy<Decl>(() => TranslationUnit.GetOrCreate<Decl>(Handle.NonClosureContext));
Expand Down Expand Up @@ -90,7 +94,11 @@ private protected Decl(CXCursor handle, CXCursorKind expectedCursorKind, CX_Decl

public IReadOnlyList<Decl> Decls => _decls.Value;

public TemplateDecl DescribedTemplate => _describedTemplate.Value;
/// <summary>
/// Per clang documentation: This returns null for partial specializations, because they are not modeled as TemplateDecls.
/// Use DescribedTemplateParams to handle those cases.
/// </summary>
public TemplateDecl? DescribedTemplate => _describedTemplate.Value;

public bool HasAttrs => Handle.HasAttrs;

Expand Down