Skip to content

Commit

Permalink
Rewrite the ClangSharpPInvokeGenerator to allow better reuse and to b…
Browse files Browse the repository at this point in the history
…e more explicit (#34)

* Performing some cleanup of the OOP methods, primarily to fix debugging

* Adding a launchSettings.json so that F5 regenerates ClangSharp

* Rewriting ClangSharpPInvokeGenerator

* Regenerating ClangSharp and updating OOP extensions

* Removing the dependency on S.R.CompilerServices.Unsafe and fixing the launchSettings to be machine independent
  • Loading branch information
tannergooding authored Apr 26, 2019
1 parent 131925a commit 4021b87
Show file tree
Hide file tree
Showing 23 changed files with 3,023 additions and 2,215 deletions.
2 changes: 0 additions & 2 deletions ClangSharp/Extensions/CXComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public partial struct CXComment

public CXComment GetChild(uint index) => clang.Comment_getChild(this, index);

public CXTranslationUnit GetTranslationUnit() => new CXTranslationUnit(TranslationUnit);

public CXString HtmlStartTag_GetAttrName(uint index) => clang.HTMLStartTag_getAttrName(this, index);

public CXString HtmlStartTag_GetAttrValue(uint index) => clang.HTMLStartTag_getAttrValue(this, index);
Expand Down
8 changes: 5 additions & 3 deletions ClangSharp/Extensions/CXCursor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public partial struct CXCursor : IEquatable<CXCursor>

public bool IsBitField => clang.Cursor_isBitField(this) != 0;

public bool IsCanonical => this.Equals(CanonicalCursor);

public bool IsDeclaration => clang.isDeclaration(Kind) != 0;

public bool IsDefinition => clang.isCursorDefinition(this) != 0;
Expand All @@ -98,7 +100,7 @@ public partial struct CXCursor : IEquatable<CXCursor>

public bool IsObjCOptional => clang.Cursor_isObjCOptional(this) != 0;

public bool IsPreProcessing => clang.isPreprocessing(Kind) != 0;
public bool IsPreprocessing => clang.isPreprocessing(Kind) != 0;

public bool IsReference => clang.isReference(Kind) != 0;

Expand Down Expand Up @@ -150,8 +152,6 @@ public partial struct CXCursor : IEquatable<CXCursor>

public CXString RawCommentText => clang.Cursor_getRawCommentText(this);

public CXType RecieverType => clang.Cursor_getReceiverType(this);

public CXCursor Referenced => clang.getCursorReferenced(this);

public CXType ResultType => clang.getCursorResultType(this);
Expand Down Expand Up @@ -201,6 +201,8 @@ public bool GetIsExternalSymbol(out CXString language, out CXString definedIn, o

public int GetPlatformAvailability(out bool alwaysDeprecated, out CXString deprecatedMessage, out bool alwaysUnavailable, out CXString unavailableMessage, CXPlatformAvailability[] availability) => clang.getCursorPlatformAvailability(this, out alwaysDeprecated, out deprecatedMessage, out alwaysUnavailable, out unavailableMessage, availability, availability.Length);

public CXType GetRecieverType() => clang.Cursor_getReceiverType(this);

public CXSourceRange GetReferenceNameRange(CXNameRefFlags nameFlags, uint pieceIndex) => clang.getCursorReferenceNameRange(this, (uint)nameFlags, pieceIndex);

public CXSourceRange GetSpellingNameRange(uint pieceIndex, uint options) => clang.Cursor_getSpellingNameRange(this, pieceIndex, options);
Expand Down
2 changes: 2 additions & 0 deletions ClangSharp/Extensions/CXModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public partial struct CXModule
public uint GetNumTopLevelHeaders(CXTranslationUnit translationUnit) => clang.Module_getNumTopLevelHeaders(translationUnit, this);

public CXFile GetTopLevelHeader(CXTranslationUnit translationUnit, uint index) => clang.Module_getTopLevelHeader(translationUnit, this, index);

public override string ToString() => FullName.ToString();
}
}
6 changes: 6 additions & 0 deletions ClangSharp/Extensions/CXSourceLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ public partial struct CXSourceLocation : IEquatable<CXSourceLocation>
public void GetPresumedLocation(out CXString fileName, out uint line, out uint column) => clang.getPresumedLocation(this, out fileName, out line, out column);

public void GetSpellingLocation(out CXFile file, out uint line, out uint column, out uint offset) => clang.getSpellingLocation(this, out file, out line, out column, out offset);

public override string ToString()
{
GetFileLocation(out var file, out var line, out var column, out _);
return $"Line {line}, Column {column} in {file}";
}
}
}
5 changes: 5 additions & 0 deletions ClangSharp/Extensions/CXSourceRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ public partial struct CXSourceRange : IEquatable<CXSourceRange>
public override bool Equals(object obj) => (obj is CXSourceRange other) && Equals(other);

public bool Equals(CXSourceRange other) => clang.equalRanges(this, other) != 0;

public override string ToString()
{
return $"{Start} to {End}";
}
}
}
1 change: 1 addition & 0 deletions ClangSharp/Extensions/CXSourceRangeList.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace ClangSharp
{
Expand Down
3 changes: 2 additions & 1 deletion ClangSharp/Extensions/CXTranslationUnit.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Runtime.CompilerServices;

namespace ClangSharp
{
Expand Down Expand Up @@ -48,7 +49,7 @@ public partial struct CXTranslationUnit : IDisposable

public CXFile GetFile(string fileName) => clang.getFile(this, fileName);

public string GetFileContents(CXFile file, out ulong size) => clang.getFileContents(this, file, out size);
public string GetFileContents(CXFile file, out IntPtr size) => clang.getFileContents(this, file, out size);

public void GetInclusions(CXInclusionVisitor visitor, CXClientData clientData) => clang.getInclusions(this, visitor, clientData);

Expand Down
14 changes: 8 additions & 6 deletions ClangSharp/Extensions/CXType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace ClangSharp
{
public partial struct CXType : IEquatable<CXType>
{
public uint AddressSpace => clang.getAddressSpace(this);

public long AlignOf => clang.Type_getAlignOf(this);

public CXType ArrayElementType => clang.getArrayElementType(this);
Expand All @@ -26,6 +24,8 @@ public partial struct CXType : IEquatable<CXType>

public CXCallingConv FunctionTypeCallingConv => clang.getFunctionTypeCallingConv(this);

public bool IsCanonical => this.Equals(CanonicalType);

public bool IsConstQualified => clang.isConstQualifiedType(this) != 0;

public bool IsFunctionTypeVariadic => clang.isFunctionTypeVariadic(this) != 0;
Expand Down Expand Up @@ -58,22 +58,22 @@ public partial struct CXType : IEquatable<CXType>

public CXType ObjCObjectBaseType => clang.Type_getObjCObjectBaseType(this);

public CXString ObjCEncoding => clang.Type_getObjCEncoding(this);

public CXType PointeeType => clang.getPointeeType(this);

public CXType ResultType => clang.getResultType(this);

public long SizeOf => clang.Type_getSizeOf(this);

public CXString TypedefName => clang.getTypedefName(this);

public override bool Equals(object obj) => (obj is CXType other) && Equals(other);

public bool Equals(CXType other) => clang.equalTypes(this, other) != 0;

public uint GetAddressSpace() => clang.getAddressSpace(this);

public CXType GetArgType(uint i) => clang.getArgType(this, i);

public CXString GetObjCEncoding() => clang.Type_getObjCEncoding(this);

public CXCursor GetObjCProtocolDecl(uint i) => clang.Type_getObjCProtocolDecl(this, i);

public CXType GetObjCTypeArg(uint i) => clang.Type_getObjCTypeArg(this, i);
Expand All @@ -82,6 +82,8 @@ public partial struct CXType : IEquatable<CXType>

public CXType GetTemplateArgumentAsType(uint i) => clang.Type_getTemplateArgumentAsType(this, i);

public CXString GetTypedefName() => clang.getTypedefName(this);

public CXString Spelling => clang.getTypeSpelling(this);

public override string ToString() => Spelling.ToString();
Expand Down
2 changes: 1 addition & 1 deletion ClangSharp/Generated.Custom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private static void BeginCXUnsavedFileMarshal(ref _CXUnsavedFile[] arr, ref CXUn
int size = arr.Length;
for (int i = 0; i < size; ++i)
{
arr[i].Length = unsaved_files[i].Length;
arr[i].Length = (int)unsaved_files[i].Length;
arr[i].Filename = Marshal.StringToHGlobalAnsi(unsaved_files[i].Filename);
arr[i].Contents = Marshal.StringToHGlobalAnsi(unsaved_files[i].Contents);
}
Expand Down
Loading

0 comments on commit 4021b87

Please sign in to comment.