Skip to content

Commit

Permalink
Merge pull request #530 from ceresgalax/bug_decl_dt_nullable
Browse files Browse the repository at this point in the history
Make Decl.DescribedTemplate property nullable.
  • Loading branch information
tannergooding authored May 15, 2024
2 parents be6c8f8 + 7a0bac9 commit 305eff5
Showing 1 changed file with 11 additions and 3 deletions.
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

0 comments on commit 305eff5

Please sign in to comment.