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

Cleanup how the PInvokeGenerator handles CXType and resolves names #61

Merged
merged 6 commits into from
Jun 6, 2019
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
6 changes: 2 additions & 4 deletions sources/ClangSharp.PInvokeGenerator/Cursors/Decls/EnumDecl.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;

Expand All @@ -7,17 +6,16 @@ namespace ClangSharp
internal sealed class EnumDecl : TagDecl
{
private readonly List<EnumConstantDecl> _enumerators = new List<EnumConstantDecl>();
private readonly Lazy<Type> _integerType;

public EnumDecl(CXCursor handle, Cursor parent) : base(handle, parent)
{
Debug.Assert(handle.Kind == CXCursorKind.CXCursor_EnumDecl);
_integerType = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.EnumDecl_IntegerType, () => Type.Create(Handle.EnumDecl_IntegerType, TranslationUnit)));
IntegerType = TranslationUnit.GetOrCreateType(Handle.EnumDecl_IntegerType, () => Type.Create(Handle.EnumDecl_IntegerType, TranslationUnit));
}

public IReadOnlyList<EnumConstantDecl> Enumerators => _enumerators;

public Type IntegerType => _integerType.Value;
public Type IntegerType { get; }

public bool IsScoped => Handle.EnumDecl_IsScoped;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand All @@ -9,7 +9,6 @@ internal class FunctionDecl : DeclaratorDecl
{
private readonly List<Decl> _declarations = new List<Decl>();
private readonly ParmVarDecl[] _parameters;
private readonly Lazy<Type> _returnType;
private readonly Lazy<Cursor> _specializedTemplate;

private Stmt _body;
Expand All @@ -27,7 +26,7 @@ public FunctionDecl(CXCursor handle, Cursor parent) : base(handle, parent)
parmVarDecl.Visit(clientData: default);
}

_returnType = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.ResultType, () => Type.Create(Handle.ResultType, TranslationUnit)));
ReturnType = TranslationUnit.GetOrCreateType(Handle.ResultType, () => Type.Create(Handle.ResultType, TranslationUnit));

_specializedTemplate = new Lazy<Cursor>(() => {
var cursor = TranslationUnit.GetOrCreateCursor(Handle.SpecializedCursorTemplate, () => Create(Handle.SpecializedCursorTemplate, this));
Expand All @@ -42,6 +41,8 @@ public FunctionDecl(CXCursor handle, Cursor parent) : base(handle, parent)

public string DisplayName => Handle.DisplayName.ToString();

public FunctionType FunctionType => (FunctionType)Type;

public bool HasDllExport => HasAttrs && Attributes.Any((attr) => attr is DLLExport);

public bool HasDllImport => HasAttrs && Attributes.Any((attr) => attr is DLLImport);
Expand All @@ -56,7 +57,7 @@ public FunctionDecl(CXCursor handle, Cursor parent) : base(handle, parent)

public IReadOnlyList<ParmVarDecl> Parameters => _parameters;

public Type ReturnType => _returnType.Value;
public Type ReturnType { get; }

public Cursor SpecializedTemplate => _specializedTemplate.Value;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System;
using System.Diagnostics;

namespace ClangSharp
{
internal sealed class FunctionTemplateDecl : RedeclarableTemplateDecl
{
private readonly Lazy<Type> _type;

public FunctionTemplateDecl(CXCursor handle, Cursor parent) : base(handle, parent)
{
Debug.Assert(handle.Kind == CXCursorKind.CXCursor_FunctionTemplate);
_type = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit)));
Type = TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit));
}

public Type Type => _type.Value;
public Type Type { get; }
}
}
8 changes: 2 additions & 6 deletions sources/ClangSharp.PInvokeGenerator/Cursors/Decls/TypeDecl.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;

namespace ClangSharp
{
internal class TypeDecl : NamedDecl
{
private readonly Lazy<Type> _type;

protected TypeDecl(CXCursor handle, Cursor parent) : base(handle, parent)
{
_type = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit)));
Type = TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit));
}

public Type Type => _type.Value;
public Type Type { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;

namespace ClangSharp
{
internal class TypedefNameDecl : TypeDecl
{
private readonly Lazy<Type> _underlyingType;

protected TypedefNameDecl(CXCursor handle, Cursor parent) : base(handle, parent)
{
_underlyingType = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.TypedefDeclUnderlyingType, () => Type.Create(Handle.TypedefDeclUnderlyingType, TranslationUnit)));
UnderlyingType = TranslationUnit.GetOrCreateType(Handle.TypedefDeclUnderlyingType, () => Type.Create(Handle.TypedefDeclUnderlyingType, TranslationUnit));
}

public Type UnderlyingType => _underlyingType.Value;
public Type UnderlyingType { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;

namespace ClangSharp
{
internal class ValueDecl : NamedDecl
{
private readonly Lazy<Type> _type;

protected ValueDecl(CXCursor handle, Cursor parent) : base(handle, parent)
{
_type = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit)));
Type = TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit));
}

public Type Type => _type.Value;
public Type Type { get; }
}
}
8 changes: 4 additions & 4 deletions sources/ClangSharp.PInvokeGenerator/Cursors/Exprs/Expr.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;

namespace ClangSharp
Expand Down Expand Up @@ -144,7 +144,6 @@ internal class Expr : ValueStmt
}

private readonly Lazy<Cursor> _definition;
private readonly Lazy<Type> _type;

protected Expr(CXCursor handle, Cursor parent) : base(handle, parent)
{
Expand All @@ -155,14 +154,15 @@ protected Expr(CXCursor handle, Cursor parent) : base(handle, parent)
cursor?.Visit(clientData: default);
return cursor;
});
_type = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit)));

Type = TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit));
}

public Cursor Definition => _definition.Value;

public bool IsDynamicCall => Handle.IsDynamicCall;

public Type Type => _type.Value;
public Type Type { get; }

protected override void ValidateVisit(ref CXCursor handle)
{
Expand Down
8 changes: 4 additions & 4 deletions sources/ClangSharp.PInvokeGenerator/Cursors/Refs/Ref.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Diagnostics;

namespace ClangSharp
Expand Down Expand Up @@ -50,7 +50,6 @@ internal class Ref : Cursor

private readonly Lazy<Cursor> _definition;
private readonly Lazy<Cursor> _referenced;
private readonly Lazy<Type> _type;

protected Ref(CXCursor handle, Cursor parent) : base(handle, parent)
{
Expand All @@ -66,13 +65,14 @@ protected Ref(CXCursor handle, Cursor parent) : base(handle, parent)
cursor?.Visit(clientData: default);
return cursor;
});
_type = new Lazy<Type>(() => TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit)));

Type = TranslationUnit.GetOrCreateType(Handle.Type, () => Type.Create(Handle.Type, TranslationUnit));
}

public Cursor Definition => _definition.Value;

public Cursor Referenced => _referenced.Value;

public Type Type => _type.Value;
public Type Type { get; }
}
}
Loading