-
Couldn't load subscription status.
- Fork 166
Abstract away output mechanisms & add support for XML dumps #206
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
Merged
Merged
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a4f8d3d
Start of XML output
Perksey a31cf58
Continuation of XML output
Perksey 52a599b
Add Rider stuff to the .gitignore
Perksey 97d0bc5
Start breaking the ice on COM
Perksey 4d616d9
Finished(?) structs with COM helpers
Perksey f2f9c60
It builds!
Perksey b731d68
Change to om
Perksey 6abed31
Fix NRE
Perksey 5839eaa
Initial set of fixes
Perksey 5067c52
C# fixes
Perksey f02ea2f
XML fixes
Perksey c68af8d
Internalise
Perksey 45d6fd8
Internalise OutputBuilderFactory
Perksey 1159f39
Fix some tests
Perksey 13a791a
Be more stern with our dividers
Perksey ae28f46
Continued
Perksey 442e42a
Revert "Continued"
Perksey a4c191f
Try hacking something together
Perksey 53c2750
Move
Perksey 150d692
Try again
Perksey 4e7a0f0
Boolean logic is failing me
Perksey 6442664
Somewhat hacky fix but it makes sense
Perksey 32ddd9a
ConstantDesc
Perksey c53ad60
FieldDesc
Perksey bdb75fb
Flags
Perksey f11382c
Update FunctionOrDelegateDesc.cs
Perksey a8f1191
Update FunctionOrDelegateDesc.cs
Perksey 398708e
Update StructDesc.cs
Perksey a4b16f4
Accessibility enums?
Perksey 3194999
Calling convention enum
Perksey f44fd1a
Merge remote-tracking branch 'origin/master' into feature/xml
tannergooding 5c874f6
Set vtbl methods as unsafe by default
Perksey fe47eac
Ensure "unsafe" is inserted for standalone delegates
tannergooding 1c6f0d3
Merge remote-tracking branch 'origin/master' into feature/xml
tannergooding c13e4ea
Ensure unsafe isn't emitted on the method class due to vtbl helper me…
tannergooding File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
sources/ClangSharp.PInvokeGenerator/Abstractions/ConstantDesc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal struct ConstantDesc | ||
| { | ||
| public string AccessSpecifier { get; set; } | ||
| public string TypeName { get; set; } | ||
| public string EscapedName { get; set; } | ||
| public string NativeTypeName { get; set; } | ||
| public ConstantKind Kind { get; set; } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
sources/ClangSharp.PInvokeGenerator/Abstractions/ConstantKind.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| [Flags] | ||
| internal enum ConstantKind | ||
| { | ||
| None = 0, | ||
| ReadOnly = 1 << 0, | ||
| Enumerator = 1 << 1, | ||
| PrimitiveConstant = 1 << 2, | ||
| NonPrimitiveConstant = 1 << 3 | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
sources/ClangSharp.PInvokeGenerator/Abstractions/FieldDesc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal struct FieldDesc | ||
| { | ||
| public string AccessSpecifier { get; set; } | ||
| public string NativeTypeName { get; set; } | ||
| public string EscapedName { get; set; } | ||
| public int? Offset { get; set; } | ||
| public bool NeedsNewKeyword { get; set; } | ||
| public string InheritedFrom { get; set; } | ||
| } | ||
| } |
114 changes: 114 additions & 0 deletions
114
sources/ClangSharp.PInvokeGenerator/Abstractions/FunctionOrDelegateDesc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| using System; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal struct FunctionOrDelegateDesc<TCustomAttrGeneratorData> | ||
| { | ||
| public string AccessSpecifier { get; set; } | ||
| public string NativeTypeName { get; set; } | ||
| public string EscapedName { get; set; } | ||
| public string EntryPoint { get; set; } | ||
| public string CallingConventionName { get; set; } | ||
| public string LibraryPath { get; set; } | ||
| public FunctionOrDelegateFlags Flags { get; set; } | ||
|
|
||
| public bool IsVirtual | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsVirtual) != 0; | ||
| set => Flags = | ||
| value ? Flags | FunctionOrDelegateFlags.IsVirtual : Flags & FunctionOrDelegateFlags.IsVirtual; | ||
| } | ||
|
|
||
| public bool IsDllImport | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsDllImport) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.IsDllImport | ||
| : Flags & FunctionOrDelegateFlags.IsDllImport; | ||
| } | ||
|
|
||
| public bool HasFnPtrCodeGen | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.HasFnPtrCodeGen) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.HasFnPtrCodeGen | ||
| : Flags & FunctionOrDelegateFlags.HasFnPtrCodeGen; | ||
| } | ||
|
|
||
| public bool IsAggressivelyInlined | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsAggressivelyInlined) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.IsAggressivelyInlined | ||
| : Flags & FunctionOrDelegateFlags.IsAggressivelyInlined; | ||
| } | ||
|
|
||
| public bool SetLastError | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.SetLastError) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.SetLastError | ||
| : Flags & FunctionOrDelegateFlags.SetLastError; | ||
| } | ||
|
|
||
| public bool IsCxx | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsCxx) != 0; | ||
| set => Flags = value ? Flags | FunctionOrDelegateFlags.IsCxx : Flags & FunctionOrDelegateFlags.IsCxx; | ||
| } | ||
|
|
||
| public bool NeedsNewKeyword | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.NeedsNewKeyword) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.NeedsNewKeyword | ||
| : Flags & FunctionOrDelegateFlags.NeedsNewKeyword; | ||
| } | ||
|
|
||
| public bool IsUnsafe | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsUnsafe) != 0; | ||
| set => Flags = value ? Flags | FunctionOrDelegateFlags.IsUnsafe : Flags & FunctionOrDelegateFlags.IsUnsafe; | ||
| } | ||
|
|
||
| public bool IsCtxCxxRecord | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsCtxCxxRecord) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.IsCtxCxxRecord | ||
| : Flags & FunctionOrDelegateFlags.IsCtxCxxRecord; | ||
| } | ||
|
|
||
| public bool IsCxxRecordCtxUnsafe | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsCxxRecordCtxUnsafe) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.IsCxxRecordCtxUnsafe | ||
| : Flags & FunctionOrDelegateFlags.IsCxxRecordCtxUnsafe; | ||
| } | ||
|
|
||
| public bool IsMemberFunction | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsMemberFunction) != 0; | ||
| set => Flags = value | ||
| ? Flags | FunctionOrDelegateFlags.IsMemberFunction | ||
| : Flags & FunctionOrDelegateFlags.IsMemberFunction; | ||
| } | ||
|
|
||
| public bool? IsStatic | ||
| { | ||
| get => (Flags & FunctionOrDelegateFlags.IsStatic) != 0 ? true : | ||
| (Flags & FunctionOrDelegateFlags.IsNotStatic) != 0 ? false : null; | ||
| set => Flags = value switch | ||
| { | ||
| // true - static, false - not static, null - infer | ||
| true => Flags | FunctionOrDelegateFlags.IsStatic & FunctionOrDelegateFlags.IsNotStatic, | ||
| false => Flags & FunctionOrDelegateFlags.IsStatic | FunctionOrDelegateFlags.IsNotStatic, | ||
| null => Flags & FunctionOrDelegateFlags.IsStatic & FunctionOrDelegateFlags.IsNotStatic | ||
| }; | ||
| } | ||
|
|
||
| public Action<TCustomAttrGeneratorData> WriteCustomAttrs { get; set; } | ||
| public TCustomAttrGeneratorData CustomAttrGeneratorData { get; set; } | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.Visit.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal partial interface IOutputBuilder | ||
| { | ||
| void WriteDivider(bool force = false); | ||
| void SuppressDivider(); | ||
|
|
||
| void WriteCustomAttribute(string attribute); | ||
| void WriteIid(string iidName, string iidValue); | ||
| void EmitUsingDirective(string directive); | ||
| } | ||
| } |
80 changes: 80 additions & 0 deletions
80
sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.VisitDecl.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using ClangSharp.CSharp; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal partial interface IOutputBuilder | ||
| { | ||
| void BeginInnerValue(); | ||
| void EndInnerValue(); | ||
|
|
||
| void BeginInnerCast(); | ||
| void WriteCastType(string targetTypeName); | ||
| void EndInnerCast(); | ||
|
|
||
| void BeginUnchecked(); | ||
| void EndUnchecked(); | ||
|
|
||
| void BeginConstant(in ConstantDesc desc); | ||
| void BeginConstantValue(bool isGetOnlyProperty = false); | ||
| void WriteConstantValue(long value); | ||
| void WriteConstantValue(ulong value); | ||
| void EndConstantValue(); | ||
| void EndConstant(bool isConstant); | ||
|
|
||
| void BeginEnum(string accessSpecifier, string typeName, string escapedName, string nativeTypeName); | ||
| void EndEnum(); | ||
|
|
||
| void BeginField(in FieldDesc desc); | ||
| void WriteFixedCountField(string typeName, string escapedName, string fixedName, string count); | ||
| void WriteRegularField(string typeName, string escapedName); | ||
| void EndField(bool isBodyless = true); | ||
|
|
||
| void BeginFunctionOrDelegate<TCustomAttrGeneratorData>(in FunctionOrDelegateDesc<TCustomAttrGeneratorData> info, | ||
| ref bool isMethodClassUnsafe); | ||
| void WriteReturnType(string typeString); | ||
| void BeginFunctionInnerPrototype(string escapedName); | ||
| void BeginParameter<TCustomAttrGeneratorData>(in ParameterDesc<TCustomAttrGeneratorData> info); | ||
| void BeginParameterDefault(); | ||
| void EndParameterDefault(); | ||
| void EndParameter(); | ||
| void WriteParameterSeparator(); | ||
| void EndFunctionInnerPrototype(); | ||
| void BeginConstructorInitializer(string memberRefName, string memberInitName); | ||
| void EndConstructorInitializer(); | ||
| void BeginBody(bool isExpressionBody = false); | ||
| void BeginConstructorInitializers(); | ||
| void EndConstructorInitializers(); | ||
| void BeginInnerFunctionBody(); | ||
| void EndInnerFunctionBody(); | ||
| void EndBody(bool isExpressionBody = false); | ||
| void EndFunctionOrDelegate(bool isVirtual, bool isBodyless); | ||
|
|
||
| void BeginStruct<TCustomAttrGeneratorData>(in StructDesc<TCustomAttrGeneratorData> info); | ||
| void BeginExplicitVtbl(); | ||
| void EndExplicitVtbl(); | ||
| void EndStruct(); | ||
|
|
||
| void EmitCompatibleCodeSupport(); | ||
| void EmitFnPtrSupport(); | ||
| void EmitSystemSupport(); | ||
|
|
||
| CSharpOutputBuilder BeginCSharpCode(); | ||
| void EndCSharpCode(CSharpOutputBuilder output); | ||
|
|
||
| void BeginGetter(bool aggressivelyInlined); | ||
| void EndGetter(); | ||
| void BeginSetter(bool aggressivelyInlined); | ||
| void EndSetter(); | ||
|
|
||
| void BeginIndexer(string accessSpecifier, bool isUnsafe); | ||
| void WriteIndexer(string typeName); | ||
| void BeginIndexerParameters(); | ||
| void EndIndexerParameters(); | ||
| void EndIndexer(); | ||
|
|
||
| void BeginDereference(); | ||
| void EndDereference(); | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
sources/ClangSharp.PInvokeGenerator/Abstractions/IOutputBuilder.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal partial interface IOutputBuilder | ||
| { | ||
| bool IsTestOutput { get; } | ||
| string Name { get; } | ||
| string Extension { get; } | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
sources/ClangSharp.PInvokeGenerator/Abstractions/ParameterDesc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal struct ParameterDesc<TCustomAttrGeneratorData> | ||
| { | ||
| public string Type { get; set; } | ||
| public string Name { get; set; } | ||
| public string NativeTypeName { get; set; } | ||
| public IEnumerable<string> CppAttributes { get; set; } | ||
| public Action<TCustomAttrGeneratorData> WriteCustomAttrs { get; set; } | ||
| public TCustomAttrGeneratorData CustomAttrGeneratorData { get; set; } | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
sources/ClangSharp.PInvokeGenerator/Abstractions/StructDesc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| internal struct StructDesc<TCustomAttrGeneratorData> | ||
| { | ||
| public string AccessSpecifier { get; set; } | ||
| public string EscapedName { get; set; } | ||
| public string NativeType { get; set; } | ||
| public string NativeInheritance { get; set; } | ||
| public StructLayoutAttribute Layout { get; set; } | ||
| public Guid? Uuid { get; set; } | ||
| public StructFlags Flags { get; set; } | ||
|
|
||
| public bool IsUnsafe | ||
| { | ||
| get => (Flags & StructFlags.IsUnsafe) != 0; | ||
| set => Flags = value ? Flags | StructFlags.IsUnsafe : Flags ^ StructFlags.IsUnsafe; | ||
| } | ||
|
|
||
| public bool HasVtbl | ||
| { | ||
| get => (Flags & StructFlags.HasVtbl) != 0; | ||
| set => Flags = value ? Flags | StructFlags.HasVtbl : Flags ^ StructFlags.HasVtbl; | ||
| } | ||
|
|
||
| public Action<TCustomAttrGeneratorData> WriteCustomAttrs { get; set; } | ||
| public TCustomAttrGeneratorData CustomAttrGeneratorData { get; set; } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
sources/ClangSharp.PInvokeGenerator/Abstractions/StructFlags.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using System; | ||
|
|
||
| namespace ClangSharp.Abstractions | ||
| { | ||
| [Flags] | ||
| public enum StructFlags | ||
| { | ||
| IsUnsafe = 1 << 0, | ||
| HasVtbl = 1 << 1 | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
sources/ClangSharp.PInvokeGenerator/CSharp/CSharpOutputBuilder.Visit.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| namespace ClangSharp.CSharp | ||
| { | ||
| internal partial class CSharpOutputBuilder | ||
| { | ||
| private bool _customAttrIsForParameter = false; | ||
| public void WriteCustomAttribute(string attribute) | ||
| { | ||
| if (attribute.Equals("Flags") || attribute.Equals("Obsolete")) | ||
| { | ||
| AddUsingDirective("System"); | ||
| } | ||
| else if (attribute.Equals("EditorBrowsable") || attribute.StartsWith("EditorBrowsable(")) | ||
| { | ||
| AddUsingDirective("System.ComponentModel"); | ||
| } | ||
| else if (attribute.StartsWith("Guid(")) | ||
| { | ||
| AddUsingDirective("System.Runtime.InteropServices"); | ||
| } | ||
|
|
||
| if (!_customAttrIsForParameter) | ||
| { | ||
| WriteIndented('['); | ||
| Write(attribute); | ||
| WriteLine(']'); | ||
| } | ||
| else | ||
| { | ||
| Write('['); | ||
| Write(attribute); | ||
| Write(']'); | ||
| Write(' '); | ||
| } | ||
| } | ||
|
|
||
| public void WriteDivider(bool force = false) | ||
| { | ||
| if (force) | ||
| { | ||
| WriteNewline(); | ||
| } | ||
| else | ||
| { | ||
| NeedsNewline = true; | ||
| } | ||
| } | ||
|
|
||
| public void SuppressDivider() | ||
| { | ||
| NeedsNewline = false; | ||
| } | ||
|
|
||
| public void WriteIid(string iidName, string iidValue) | ||
| { | ||
| AddUsingDirective("System"); | ||
| WriteIndented("public static readonly Guid "); | ||
| Write(iidName); | ||
| Write(" = new Guid("); | ||
| Write(iidValue); | ||
| Write(")"); | ||
| WriteSemicolon(); | ||
| WriteNewline(); | ||
| } | ||
|
|
||
| public void EmitUsingDirective(string directive) => AddUsingDirective(directive); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.