Skip to content
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
16 changes: 14 additions & 2 deletions sources/ClangSharp/Cursors/Decls/BlockDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public sealed partial class BlockDecl : Decl, IDeclContext
internal unsafe BlockDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Block)
{
_blockManglingContextDecl = new ValueLazy<BlockDecl, Decl>(&BlockManglingContextDeclFactory);
_captures = LazyList.Create<Capture>(Handle.NumCaptures, (i) => new Capture(this, unchecked((uint)i)));
_parameters = LazyList.Create<ParmVarDecl>(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate<ParmVarDecl>(Handle.GetArgument(unchecked((uint)i))));
_captures = LazyList.Create<Capture>(this, Handle.NumCaptures, &CapturesFactory);
_parameters = LazyList.Create<ParmVarDecl>(this, Handle.NumArguments, &ParametersFactory);
}

public Decl BlockManglingContextDecl => _blockManglingContextDecl.GetValue(this);
Expand Down Expand Up @@ -55,4 +55,16 @@ internal unsafe BlockDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl
public bool CapturesVariable(VarDecl var) => Handle.CapturesVariable((var is not null) ? var.Handle : CXCursor.Null);

private static unsafe Decl BlockManglingContextDeclFactory(BlockDecl self) => self.TranslationUnit.GetOrCreate<Decl>(self.Handle.BlockManglingContextDecl);

private static unsafe Capture CapturesFactory(object self, int i)
{
var @this = (BlockDecl)self;
return new Capture(@this, unchecked((uint)i));
}

private static unsafe ParmVarDecl ParametersFactory(object self, int i)
{
var @this = (BlockDecl)self;
return @this.TranslationUnit.GetOrCreate<ParmVarDecl>(@this.Handle.GetArgument(unchecked((uint)i)));
}
}
8 changes: 7 additions & 1 deletion sources/ClangSharp/Cursors/Decls/CXXConstructorDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class CXXConstructorDecl : CXXMethodDecl
internal unsafe CXXConstructorDecl(CXCursor handle) : base(handle, CXCursor_Constructor, CX_DeclKind_CXXConstructor)
{
_inheritedConstructor = new ValueLazy<CXXConstructorDecl, CXXConstructorDecl>(&InheritedConstructorFactory);
_initExprs = LazyList.Create<Expr>(Handle.NumExprs , (i) => TranslationUnit.GetOrCreate<Expr>(Handle.GetExpr(unchecked((uint)i))));
_initExprs = LazyList.Create<Expr>(this, Handle.NumExprs, &InitExprsFactory);
}

public new CXXConstructorDecl CanonicalDecl => (CXXConstructorDecl)base.CanonicalDecl;
Expand Down Expand Up @@ -58,4 +58,10 @@ public CXXConstructorDecl? TargetConstructor
}

private static unsafe CXXConstructorDecl InheritedConstructorFactory(CXXConstructorDecl self) => self.TranslationUnit.GetOrCreate<CXXConstructorDecl>(self.Handle.InheritedConstructor);

private static unsafe Expr InitExprsFactory(object self, int i)
{
var @this = (CXXConstructorDecl)self;
return @this.TranslationUnit.GetOrCreate<Expr>(@this.Handle.GetExpr(unchecked((uint)i)));
}
}
8 changes: 7 additions & 1 deletion sources/ClangSharp/Cursors/Decls/CXXMethodDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private protected unsafe CXXMethodDecl(CXCursor handle, CXCursorKind expectedCur
throw new ArgumentOutOfRangeException(nameof(handle));
}

_overriddenMethods = LazyList.Create<CXXMethodDecl>(Handle.NumMethods, (i) => TranslationUnit.GetOrCreate<CXXMethodDecl>(Handle.GetMethod(unchecked((uint)i))));
_overriddenMethods = LazyList.Create<CXXMethodDecl>(this, Handle.NumMethods, &OverriddenMethodsFactory);
_thisType = new ValueLazy<CXXMethodDecl, Type>(&ThisTypeFactory);
_thisObjectType = new ValueLazy<CXXMethodDecl, Type>(&ThisObjectTypeFactory);
}
Expand Down Expand Up @@ -57,4 +57,10 @@ private protected unsafe CXXMethodDecl(CXCursor handle, CXCursorKind expectedCur
private static unsafe Type ThisObjectTypeFactory(CXXMethodDecl self) => self.TranslationUnit.GetOrCreate<Type>(self.Handle.ThisObjectType);

private static unsafe Type ThisTypeFactory(CXXMethodDecl self) => self.TranslationUnit.GetOrCreate<Type>(self.Handle.ThisType);

private static unsafe CXXMethodDecl OverriddenMethodsFactory(object self, int i)
{
var @this = (CXXMethodDecl)self;
return @this.TranslationUnit.GetOrCreate<CXXMethodDecl>(@this.Handle.GetMethod(unchecked((uint)i)));
}
}
40 changes: 35 additions & 5 deletions sources/ClangSharp/Cursors/Decls/CXXRecordDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ private protected unsafe CXXRecordDecl(CXCursor handle, CXCursorKind expectedCur
throw new ArgumentOutOfRangeException(nameof(handle));
}

_bases = LazyList.Create<CXXBaseSpecifier>(Handle.NumBases, (i) => TranslationUnit.GetOrCreate<CXXBaseSpecifier>(Handle.GetBase(unchecked((uint)i))));
_ctors = LazyList.Create<CXXConstructorDecl>(Handle.NumCtors, (i) => TranslationUnit.GetOrCreate<CXXConstructorDecl>(Handle.GetCtor(unchecked((uint)i))));
_bases = LazyList.Create<CXXBaseSpecifier>(this, Handle.NumBases, &BasesFactory);
_ctors = LazyList.Create<CXXConstructorDecl>(this, Handle.NumCtors, &CtorsFactory);
_dependentLambdaCallOperator = new ValueLazy<CXXRecordDecl, FunctionTemplateDecl>(&DependentLambdaCallOperatorFactory);
_describedClassTemplate = new ValueLazy<CXXRecordDecl, ClassTemplateDecl>(&DescribedClassTemplateFactory);
_destructor = new ValueLazy<CXXRecordDecl, CXXDestructorDecl?>(&DestructorFactory);
_friends = LazyList.Create<FriendDecl>(Handle.NumFriends, (i) => TranslationUnit.GetOrCreate<FriendDecl>(Handle.GetFriend(unchecked((uint)i))));
_friends = LazyList.Create<FriendDecl>(this, Handle.NumFriends, &FriendsFactory);
_instantiatedFromMemberClass = new ValueLazy<CXXRecordDecl, CXXRecordDecl>(&InstantiatedFromMemberClassFactory);
_lambdaCallOperator = new ValueLazy<CXXRecordDecl, CXXMethodDecl>(&LambdaCallOperatorFactory);
_lambdaContextDecl = new ValueLazy<CXXRecordDecl, Decl>(&LambdaContextDeclFactory);
_lambdaStaticInvoker = new ValueLazy<CXXRecordDecl, CXXMethodDecl>(&LambdaStaticInvokerFactory);
_methods = LazyList.Create<CXXMethodDecl>(Handle.NumMethods, (i) => TranslationUnit.GetOrCreate<CXXMethodDecl>(Handle.GetMethod(unchecked((uint)i))));
_methods = LazyList.Create<CXXMethodDecl>(this, Handle.NumMethods, &MethodsFactory);
_templateInstantiationPattern = new ValueLazy<CXXRecordDecl, CXXRecordDecl>(&TemplateInstantiationPatternFactory);
_vbases = LazyList.Create<CXXBaseSpecifier>(Handle.NumVBases, (i) => TranslationUnit.GetOrCreate<CXXBaseSpecifier>(Handle.GetVBase(unchecked((uint)i))));
_vbases = LazyList.Create<CXXBaseSpecifier>(this, Handle.NumVBases, &VbasesFactory);
}

public bool IsAbstract => Handle.CXXRecord_IsAbstract;
Expand Down Expand Up @@ -146,4 +146,34 @@ public CXXRecordDecl MostRecentNonInjectedDecl
private static unsafe ClassTemplateDecl DescribedClassTemplateFactory(CXXRecordDecl self) => self.TranslationUnit.GetOrCreate<ClassTemplateDecl>(self.Handle.DescribedCursorTemplate);

private static unsafe FunctionTemplateDecl DependentLambdaCallOperatorFactory(CXXRecordDecl self) => self.TranslationUnit.GetOrCreate<FunctionTemplateDecl>(self.Handle.DependentLambdaCallOperator);

private static unsafe CXXBaseSpecifier BasesFactory(object self, int i)
{
var @this = (CXXRecordDecl)self;
return @this.TranslationUnit.GetOrCreate<CXXBaseSpecifier>(@this.Handle.GetBase(unchecked((uint)i)));
}

private static unsafe CXXConstructorDecl CtorsFactory(object self, int i)
{
var @this = (CXXRecordDecl)self;
return @this.TranslationUnit.GetOrCreate<CXXConstructorDecl>(@this.Handle.GetCtor(unchecked((uint)i)));
}

private static unsafe FriendDecl FriendsFactory(object self, int i)
{
var @this = (CXXRecordDecl)self;
return @this.TranslationUnit.GetOrCreate<FriendDecl>(@this.Handle.GetFriend(unchecked((uint)i)));
}

private static unsafe CXXMethodDecl MethodsFactory(object self, int i)
{
var @this = (CXXRecordDecl)self;
return @this.TranslationUnit.GetOrCreate<CXXMethodDecl>(@this.Handle.GetMethod(unchecked((uint)i)));
}

private static unsafe CXXBaseSpecifier VbasesFactory(object self, int i)
{
var @this = (CXXRecordDecl)self;
return @this.TranslationUnit.GetOrCreate<CXXBaseSpecifier>(@this.Handle.GetVBase(unchecked((uint)i)));
}
}
8 changes: 7 additions & 1 deletion sources/ClangSharp/Cursors/Decls/CapturedDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class CapturedDecl : Decl, IDeclContext
internal unsafe CapturedDecl(CXCursor handle) : base(handle, CXCursor_UnexposedDecl, CX_DeclKind_Captured)
{
_contextParam = new ValueLazy<CapturedDecl, ImplicitParamDecl>(&ContextParamFactory);
_parameters = LazyList.Create<ImplicitParamDecl>(Handle.NumArguments, (i) => TranslationUnit.GetOrCreate<ImplicitParamDecl>(Handle.GetArgument(unchecked((uint)i))));
_parameters = LazyList.Create<ImplicitParamDecl>(this, Handle.NumArguments, &ParametersFactory);
}

public ImplicitParamDecl ContextParam => _contextParam.GetValue(this);
Expand All @@ -29,4 +29,10 @@ internal unsafe CapturedDecl(CXCursor handle) : base(handle, CXCursor_UnexposedD
public IReadOnlyList<ImplicitParamDecl> Parameters => _parameters;

private static unsafe ImplicitParamDecl ContextParamFactory(CapturedDecl self) => self.TranslationUnit.GetOrCreate<ImplicitParamDecl>(self.Handle.ContextParam);

private static unsafe ImplicitParamDecl ParametersFactory(object self, int i)
{
var @this = (CapturedDecl)self;
return @this.TranslationUnit.GetOrCreate<ImplicitParamDecl>(@this.Handle.GetArgument(unchecked((uint)i)));
}
}
8 changes: 7 additions & 1 deletion sources/ClangSharp/Cursors/Decls/ClassTemplateDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class ClassTemplateDecl : RedeclarableTemplateDecl
internal unsafe ClassTemplateDecl(CXCursor handle) : base(handle, CXCursor_ClassTemplate, CX_DeclKind_ClassTemplate)
{
_injectedClassNameSpecialization = new ValueLazy<ClassTemplateDecl, Type>(&InjectedClassNameSpecializationFactory);
_specializations = LazyList.Create<ClassTemplateSpecializationDecl>(Handle.NumSpecializations, (i) => TranslationUnit.GetOrCreate<ClassTemplateSpecializationDecl>(Handle.GetSpecialization(unchecked((uint)i))));
_specializations = LazyList.Create<ClassTemplateSpecializationDecl>(this, Handle.NumSpecializations, &SpecializationsFactory);
}

public new ClassTemplateDecl CanonicalDecl => (ClassTemplateDecl)base.CanonicalDecl;
Expand All @@ -35,4 +35,10 @@ internal unsafe ClassTemplateDecl(CXCursor handle) : base(handle, CXCursor_Class
public new CXXRecordDecl TemplatedDecl => (CXXRecordDecl)base.TemplatedDecl;

private static unsafe Type InjectedClassNameSpecializationFactory(ClassTemplateDecl self) => self.TranslationUnit.GetOrCreate<Type>(self.Handle.InjectedSpecializationType);

private static unsafe ClassTemplateSpecializationDecl SpecializationsFactory(object self, int i)
{
var @this = (ClassTemplateDecl)self;
return @this.TranslationUnit.GetOrCreate<ClassTemplateSpecializationDecl>(@this.Handle.GetSpecialization(unchecked((uint)i)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public sealed class ClassTemplatePartialSpecializationDecl : ClassTemplateSpecia

internal unsafe ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(handle, CXCursor_ClassTemplatePartialSpecialization, CX_DeclKind_ClassTemplatePartialSpecialization)
{
_associatedConstraints = LazyList.Create<Expr>(Handle.NumAssociatedConstraints, (i) => TranslationUnit.GetOrCreate<Expr>(Handle.GetAssociatedConstraint(unchecked((uint)i))));
_associatedConstraints = LazyList.Create<Expr>(this, Handle.NumAssociatedConstraints, &AssociatedConstraintsFactory);
_injectedSpecializationType = new ValueLazy<ClassTemplatePartialSpecializationDecl, Type>(&InjectedSpecializationTypeFactory);
_instantiatedFromMember = new ValueLazy<ClassTemplatePartialSpecializationDecl, ClassTemplatePartialSpecializationDecl>(&InstantiatedFromMemberFactory);
_templateParameters = LazyList.Create<NamedDecl>(Handle.GetNumTemplateParameters(0), (i) => TranslationUnit.GetOrCreate<NamedDecl>(Handle.GetTemplateParameter(0, unchecked((uint)i))));
_templateParameters = LazyList.Create<NamedDecl>(this, Handle.GetNumTemplateParameters(0), &TemplateParametersFactory);
}

public IReadOnlyList<Expr> AssociatedConstraints => _associatedConstraints;
Expand All @@ -41,4 +41,16 @@ internal unsafe ClassTemplatePartialSpecializationDecl(CXCursor handle) : base(h
private static unsafe ClassTemplatePartialSpecializationDecl InstantiatedFromMemberFactory(ClassTemplatePartialSpecializationDecl self) => self.TranslationUnit.GetOrCreate<ClassTemplatePartialSpecializationDecl>(self.Handle.InstantiatedFromMember);

private static unsafe Type InjectedSpecializationTypeFactory(ClassTemplatePartialSpecializationDecl self) => self.TranslationUnit.GetOrCreate<Type>(self.Handle.InjectedSpecializationType);

private static unsafe Expr AssociatedConstraintsFactory(object self, int i)
{
var @this = (ClassTemplatePartialSpecializationDecl)self;
return @this.TranslationUnit.GetOrCreate<Expr>(@this.Handle.GetAssociatedConstraint(unchecked((uint)i)));
}

private static unsafe NamedDecl TemplateParametersFactory(object self, int i)
{
var @this = (ClassTemplatePartialSpecializationDecl)self;
return @this.TranslationUnit.GetOrCreate<NamedDecl>(@this.Handle.GetTemplateParameter(0, unchecked((uint)i)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ClassTemplateSpecializationDecl : CXXRecordDecl
internal unsafe ClassTemplateSpecializationDecl(CXCursor handle) : this(handle, handle.Kind, CX_DeclKind_ClassTemplateSpecialization)
{
_specializedTemplate = new ValueLazy<ClassTemplateSpecializationDecl, ClassTemplateDecl>(&SpecializedTemplateFactory);
_templateArgs = LazyList.Create<TemplateArgument>(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))));
_templateArgs = LazyList.Create<TemplateArgument>(this, Handle.NumTemplateArguments, &TemplateArgsFactory);
}

private protected unsafe ClassTemplateSpecializationDecl(CXCursor handle, CXCursorKind expectedCursorKind, CX_DeclKind expectedDeclKind) : base(handle, expectedCursorKind, expectedDeclKind)
Expand All @@ -28,7 +28,7 @@ private protected unsafe ClassTemplateSpecializationDecl(CXCursor handle, CXCurs
}

_specializedTemplate = new ValueLazy<ClassTemplateSpecializationDecl, ClassTemplateDecl>(&SpecializedTemplateFactory);
_templateArgs = LazyList.Create<TemplateArgument>(Handle.NumTemplateArguments, (i) => TranslationUnit.GetOrCreate(Handle.GetTemplateArgument(unchecked((uint)i))));
_templateArgs = LazyList.Create<TemplateArgument>(this, Handle.NumTemplateArguments, &TemplateArgsFactory);
}

public bool IsClassScopeExplicitSpecialization => IsExplicitSpecialization && (LexicalDeclContext is CXXRecordDecl);
Expand Down Expand Up @@ -69,4 +69,10 @@ public bool IsExplicitInstantiationOrSpecialization
public IReadOnlyList<TemplateArgument> TemplateArgs => _templateArgs;

private static unsafe ClassTemplateDecl SpecializedTemplateFactory(ClassTemplateSpecializationDecl self) => self.TranslationUnit.GetOrCreate<ClassTemplateDecl>(self.Handle.SpecializedCursorTemplate);

private static unsafe TemplateArgument TemplateArgsFactory(object self, int i)
{
var @this = (ClassTemplateSpecializationDecl)self;
return @this.TranslationUnit.GetOrCreate(@this.Handle.GetTemplateArgument(unchecked((uint)i)));
}
}
57 changes: 46 additions & 11 deletions sources/ClangSharp/Cursors/Decls/Decl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,10 @@ private protected unsafe Decl(CXCursor handle, CXCursorKind expectedCursorKind,
}

_asFunction = new ValueLazy<Decl, FunctionDecl>(&AsFunctionFactory);
_attrs = LazyList.Create<Attr>(Handle.NumAttrs, (i) => TranslationUnit.GetOrCreate<Attr>(Handle.GetAttr(unchecked((uint)i))));
_attrs = LazyList.Create<Attr>(this, Handle.NumAttrs, &AttrsFactory);
_body = new ValueLazy<Decl, Stmt?>(&BodyFactory);
_canonicalDecl = new ValueLazy<Decl, Decl>(&CanonicalDeclFactory);
_decls = LazyList.Create<Decl>(Handle.NumDecls, (i, previousDecl) => {
if (previousDecl is null)
{
return TranslationUnit.GetOrCreate<Decl>(Handle.GetDecl(unchecked((uint)i)));
}
else
{
return previousDecl.NextDeclInContext;
}
});
_decls = LazyList.Create<Decl>(this, Handle.NumDecls, &DeclsFactory);
_describedTemplate = new ValueLazy<Decl, TemplateDecl?>(&DescribedTemplateFactory);
_mostRecentDecl = new ValueLazy<Decl, Decl>(&MostRecentDeclFactory);
_nextDeclInContext = new ValueLazy<Decl, Decl>(&NextDeclInContextFactory);
Expand Down Expand Up @@ -276,4 +267,48 @@ public bool IsStdNamespace
private static unsafe Stmt? BodyFactory(Decl self) => !self.Handle.Body.IsNull ? self.TranslationUnit.GetOrCreate<Stmt>(self.Handle.Body) : null;

private static unsafe FunctionDecl AsFunctionFactory(Decl self) => self.TranslationUnit.GetOrCreate<FunctionDecl>(self.Handle.AsFunction);

private static unsafe Attr AttrsFactory(object self, int i)
{
var @this = (Decl)self;
return @this.TranslationUnit.GetOrCreate<Attr>(@this.Handle.GetAttr(unchecked((uint)i)));
}

private static unsafe Decl DeclsFactory(object self, int i, Decl? previousDecl)
{
var @this = (Decl)self;

if (previousDecl is null)
{
return @this.TranslationUnit.GetOrCreate<Decl>(@this.Handle.GetDecl(unchecked((uint)i)));
}
else
{
return previousDecl.NextDeclInContext;
}
}

private protected static unsafe LazyList<LazyList<NamedDecl>> CreateTemplateParameterLists(Decl self)
{
return LazyList.Create<LazyList<NamedDecl>>(self, self.Handle.NumTemplateParameterLists, &TemplateParameterListFactory);
}

private static unsafe LazyList<NamedDecl> TemplateParameterListFactory(object self, int listIndex)
{
var @this = (Decl)self;
var numTemplateParameters = @this.Handle.GetNumTemplateParameters(unchecked((uint)listIndex));
return LazyList.Create<NamedDecl>(new TemplateParameterListContext(@this, unchecked((uint)listIndex)), numTemplateParameters, &TemplateParameterFactory);
}

private static unsafe NamedDecl TemplateParameterFactory(object self, int parameterIndex)
{
var context = (TemplateParameterListContext)self;
return context.Owner.TranslationUnit.GetOrCreate<NamedDecl>(context.Owner.Handle.GetTemplateParameter(context.ListIndex, unchecked((uint)parameterIndex)));
}

private sealed class TemplateParameterListContext(Decl owner, uint listIndex)
{
public readonly Decl Owner = owner;
public readonly uint ListIndex = listIndex;
}
}
5 changes: 1 addition & 4 deletions sources/ClangSharp/Cursors/Decls/DeclaratorDecl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ private protected unsafe DeclaratorDecl(CXCursor handle, CXCursorKind expectedCu
throw new ArgumentOutOfRangeException(nameof(handle));
}

_templateParameterLists = LazyList.Create<LazyList<NamedDecl>>(Handle.NumTemplateParameterLists, (listIndex) => {
var numTemplateParameters = Handle.GetNumTemplateParameters(unchecked((uint)listIndex));
return LazyList.Create<NamedDecl>(numTemplateParameters, (parameterIndex) => TranslationUnit.GetOrCreate<NamedDecl>(Handle.GetTemplateParameter(unchecked((uint)listIndex), unchecked((uint)parameterIndex))));
});
_templateParameterLists = CreateTemplateParameterLists(this);
_trailingRequiresClause = new ValueLazy<DeclaratorDecl, Expr>(&TrailingRequiresClauseFactory);
}

Expand Down
Loading
Loading