Skip to content

Commit

Permalink
Cleanup how the PInvokeGenerator handles CXType and resolves names (#61)
Browse files Browse the repository at this point in the history
* Include launchsettings.json in the list of project files.

* Changing the PInvokeGenerator to use \n by default.

* Fixing PInvokeGenerator to use Equals rather than EndsWith when checking for multi-file

* Updating the PInvokeGenerator types to more closely match the Clang C++ hierarchy.

* Improving how type and cursor names are resolved.

* Regenerating the ClangSharp bindings.
  • Loading branch information
tannergooding authored Jun 6, 2019
1 parent 23e8db8 commit 696cb97
Show file tree
Hide file tree
Showing 33 changed files with 825 additions and 630 deletions.
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

0 comments on commit 696cb97

Please sign in to comment.