Skip to content
Permalink
Browse files

Drop support for generating "safe" code (#69)

* Changing ClangSharp to no longer support generating "safe" code.

* Simplify the number of typedefs we need to special-case.

* Adding support for matching the access specifier given in native code.

* Adding basic support for emitting an attribute which tracks the underlying native type.

* Moving the wrapper types out of the generated folder.

* Adding the NativeTypeNameAttribute file

* Removing exclusions from the GenerateClangSharp command line.

* Improving the computed native type name.

* Ensure the unsafe keyword is used on delegates when required.

* Regenerating ClangSharp and updating the extension bindings.

* Changing artificial fixed sized buffers to have internal fields.

* Removing exclusions from the GenerateLLVMSharp command line.

* Fixing the System.Memory package version to be centrally managed.

* Simplfying getting the native type name.

* Fixing up the tests to expect the NativeTypeName attribute in the right places.
  • Loading branch information...
tannergooding committed Jun 11, 2019
1 parent 9ef31f1 commit 01e36c8ca82bad64cc054b95b22ff5bda400e7e5
Showing with 2,529 additions and 1,899 deletions.
  1. +8 −0 ClangSharp.sln
  2. +1 −0 Directory.Build.targets
  3. +10 −5 sources/ClangSharp.PInvokeGenerator/Cursors/Cursor.cs
  4. +2 −2 sources/ClangSharp.PInvokeGenerator/Cursors/Exprs/Expr.cs
  5. +3 −4 sources/ClangSharp.PInvokeGenerator/Cursors/Stmts/Stmt.cs
  6. +1 −1 sources/ClangSharp.PInvokeGenerator/Diagnostic.cs
  7. +339 −631 sources/ClangSharp.PInvokeGenerator/PInvokeGenerator.cs
  8. +1 −3 sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfiguration.cs
  9. +1 −3 sources/ClangSharp.PInvokeGenerator/PInvokeGeneratorConfigurationOptions.cs
  10. +2 −0 sources/ClangSharp.PInvokeGenerator/Types/Type.cs
  11. +2 −1 sources/ClangSharp/ClangSharp.csproj
  12. +9 −3 sources/ClangSharp/Extensions/CXCompletionString.cs
  13. +39 −13 sources/ClangSharp/Extensions/CXCursor.cs
  14. +10 −3 sources/ClangSharp/Extensions/CXCursorSet.cs
  15. +26 −7 sources/ClangSharp/Extensions/CXDiagnostic.cs
  16. +11 −4 sources/ClangSharp/Extensions/CXDiagnosticSet.cs
  17. +25 −4 sources/ClangSharp/Extensions/CXEvalResult.cs
  18. +8 −2 sources/ClangSharp/Extensions/CXFile.cs
  19. +11 −4 sources/ClangSharp/Extensions/CXIndex.cs
  20. +4 −4 sources/ClangSharp/Extensions/CXModule.cs
  21. +44 −0 sources/ClangSharp/Extensions/CXModuleMapDescriptor.cs
  22. +10 −3 sources/ClangSharp/Extensions/CXPlatformAvailability.cs
  23. +51 −7 sources/ClangSharp/Extensions/CXSourceLocation.cs
  24. +10 −4 sources/ClangSharp/Extensions/CXSourceRangeList.cs
  25. +17 −3 sources/ClangSharp/Extensions/CXString.cs
  26. +11 −5 sources/ClangSharp/Extensions/CXStringSet.cs
  27. +2 −2 sources/ClangSharp/Extensions/CXTUResourceUsage.cs
  28. +21 −3 sources/ClangSharp/Extensions/CXTUResourceUsageEntry.cs
  29. +10 −3 sources/ClangSharp/Extensions/CXTargetInfo.cs
  30. +2 −2 sources/ClangSharp/Extensions/CXToken.cs
  31. +144 −33 sources/ClangSharp/Extensions/CXTranslationUnit.cs
  32. +16 −3 sources/ClangSharp/Extensions/CXType.cs
  33. +75 −6 sources/ClangSharp/Extensions/CXUnsavedFile.cs
  34. +42 −0 sources/ClangSharp/Extensions/CXVirtualFileOverlay.cs
  35. +0 −325 sources/ClangSharp/Generated.Custom.cs
  36. +0 −14 sources/ClangSharp/Generated/CXClientData.cs
  37. +5 −4 sources/ClangSharp/Generated/CXCodeCompleteResults.cs
  38. +6 −5 sources/ClangSharp/Generated/CXComment.cs
  39. +5 −2 sources/ClangSharp/Generated/CXCompletionResult.cs
  40. +0 −14 sources/ClangSharp/Generated/CXCompletionString.cs
  41. +23 −3 sources/ClangSharp/Generated/CXCursor.cs
  42. +5 −2 sources/ClangSharp/Generated/CXCursorAndRangeVisitor.cs
  43. +0 −14 sources/ClangSharp/Generated/CXCursorSet.cs
  44. +2 −1 sources/ClangSharp/Generated/CXCursorVisitor.cs
  45. +0 −14 sources/ClangSharp/Generated/CXDiagnostic.cs
  46. +0 −14 sources/ClangSharp/Generated/CXDiagnosticSet.cs
  47. +0 −14 sources/ClangSharp/Generated/CXEvalResult.cs
  48. +2 −1 sources/ClangSharp/Generated/CXFieldVisitor.cs
  49. +0 −14 sources/ClangSharp/Generated/CXFile.cs
  50. +3 −2 sources/ClangSharp/Generated/CXFileUniqueID.cs
  51. +2 −0 sources/ClangSharp/Generated/CXIdxAttrInfo.cs
  52. +5 −4 sources/ClangSharp/Generated/CXIdxBaseClassInfo.cs
  53. +8 −5 sources/ClangSharp/Generated/CXIdxCXXClassDeclInfo.cs
  54. +25 −8 sources/ClangSharp/Generated/CXIdxDeclInfo.cs
  55. +15 −7 sources/ClangSharp/Generated/CXIdxEntityInfo.cs
  56. +13 −6 sources/ClangSharp/Generated/CXIdxEntityRefInfo.cs
  57. +8 −5 sources/ClangSharp/Generated/CXIdxIBOutletCollectionAttrInfo.cs
  58. +8 −3 sources/ClangSharp/Generated/CXIdxImportedASTFileInfo.cs
  59. +10 −5 sources/ClangSharp/Generated/CXIdxIncludedFileInfo.cs
  60. +21 −3 sources/ClangSharp/Generated/CXIdxLoc.cs
  61. +11 −6 sources/ClangSharp/Generated/CXIdxObjCCategoryDeclInfo.cs
  62. +4 −4 sources/ClangSharp/Generated/CXIdxObjCContainerDeclInfo.cs
  63. +9 −6 sources/ClangSharp/Generated/CXIdxObjCInterfaceDeclInfo.cs
  64. +9 −6 sources/ClangSharp/Generated/CXIdxObjCPropertyDeclInfo.cs
  65. +5 −4 sources/ClangSharp/Generated/CXIdxObjCProtocolRefInfo.cs
  66. +5 −4 sources/ClangSharp/Generated/CXIdxObjCProtocolRefListInfo.cs
  67. +1 −1 sources/ClangSharp/Generated/CXInclusionVisitor.cs
  68. +0 −14 sources/ClangSharp/Generated/CXIndex.cs
  69. +0 −14 sources/ClangSharp/Generated/CXModule.cs
  70. +0 −14 sources/ClangSharp/Generated/CXModuleMapDescriptor.cs
  71. +5 −0 sources/ClangSharp/Generated/CXPlatformAvailability.cs
  72. +21 −3 sources/ClangSharp/Generated/CXSourceLocation.cs
  73. +23 −3 sources/ClangSharp/Generated/CXSourceRange.cs
  74. +5 −4 sources/ClangSharp/Generated/CXSourceRangeList.cs
  75. +5 −4 sources/ClangSharp/Generated/CXString.cs
  76. +5 −4 sources/ClangSharp/Generated/CXStringSet.cs
  77. +8 −5 sources/ClangSharp/Generated/CXTUResourceUsage.cs
  78. +3 −0 sources/ClangSharp/Generated/CXTUResourceUsageEntry.cs
  79. +0 −14 sources/ClangSharp/Generated/CXTargetInfo.cs
  80. +6 −5 sources/ClangSharp/Generated/CXToken.cs
  81. +0 −14 sources/ClangSharp/Generated/CXTranslationUnit.cs
  82. +21 −3 sources/ClangSharp/Generated/CXType.cs
  83. +8 −5 sources/ClangSharp/Generated/CXUnsavedFile.cs
  84. +2 −0 sources/ClangSharp/Generated/CXVersion.cs
  85. +0 −14 sources/ClangSharp/Generated/CXVirtualFileOverlay.cs
  86. +15 −0 sources/ClangSharp/Generated/IndexerCallbacks.cs
  87. +449 −211 sources/ClangSharp/Generated/clang.cs
  88. +54 −0 sources/ClangSharp/Internals/MarshaledString.cs
  89. +52 −0 sources/ClangSharp/Internals/MarshaledStringArray.cs
  90. +17 −0 sources/ClangSharp/Internals/NativeTypeNameAttribute.cs
  91. +33 −0 sources/ClangSharp/Internals/SpanExtensions.cs
  92. +0 −70 sources/ClangSharp/StringMarshaler.cs
  93. +24 −0 sources/ClangSharp/Wrappers/CXClientData.cs
  94. 0 sources/ClangSharp/{Generated → Wrappers}/CXCompilationDatabase.cs
  95. 0 sources/ClangSharp/{Generated → Wrappers}/CXCompileCommand.cs
  96. 0 sources/ClangSharp/{Generated → Wrappers}/CXCompileCommands.cs
  97. +24 −0 sources/ClangSharp/Wrappers/CXCompletionString.cs
  98. +24 −0 sources/ClangSharp/Wrappers/CXCursorSet.cs
  99. +24 −0 sources/ClangSharp/Wrappers/CXDiagnostic.cs
  100. +24 −0 sources/ClangSharp/Wrappers/CXDiagnosticSet.cs
  101. +24 −0 sources/ClangSharp/Wrappers/CXEvalResult.cs
  102. +24 −0 sources/ClangSharp/Wrappers/CXFile.cs
  103. 0 sources/ClangSharp/{Generated → Wrappers}/CXIdxClientASTFile.cs
  104. 0 sources/ClangSharp/{Generated → Wrappers}/CXIdxClientContainer.cs
  105. 0 sources/ClangSharp/{Generated → Wrappers}/CXIdxClientEntity.cs
  106. 0 sources/ClangSharp/{Generated → Wrappers}/CXIdxClientFile.cs
  107. +24 −0 sources/ClangSharp/Wrappers/CXIndex.cs
  108. 0 sources/ClangSharp/{Generated → Wrappers}/CXIndexAction.cs
  109. +24 −0 sources/ClangSharp/Wrappers/CXModule.cs
  110. +24 −0 sources/ClangSharp/Wrappers/CXModuleMapDescriptor.cs
  111. 0 sources/ClangSharp/{Generated → Wrappers}/CXPrintingPolicy.cs
  112. 0 sources/ClangSharp/{Generated → Wrappers}/CXRemapping.cs
  113. +24 −0 sources/ClangSharp/Wrappers/CXTargetInfo.cs
  114. +24 −0 sources/ClangSharp/Wrappers/CXTranslationUnit.cs
  115. +24 −0 sources/ClangSharp/Wrappers/CXVirtualFileOverlay.cs
  116. +0 −8 sources/ClangSharpPInvokeGenerator/ClangSharpPInvokeGenerator.csproj
  117. +0 −4 sources/ClangSharpPInvokeGenerator/Program.cs
  118. +3 −3 sources/ClangSharpPInvokeGenerator/Properties/launchSettings.json
  119. +1 −1 tests/ClangSharp.PInvokeGenerator.UnitTests/ClangSharp.PInvokeGenerator.UnitTests.csproj
  120. +29 −3 tests/ClangSharp.PInvokeGenerator.UnitTests/EnumDeclarationTest.cs
  121. +7 −6 tests/ClangSharp.PInvokeGenerator.UnitTests/FunctionDeclarationBodyImportTest.cs
  122. +5 −7 tests/ClangSharp.PInvokeGenerator.UnitTests/PInvokeGeneratorTest.cs
  123. +202 −132 tests/ClangSharp.PInvokeGenerator.UnitTests/StructDeclarationTest.cs
  124. +25 −5 tests/ClangSharp.PInvokeGenerator.UnitTests/VarDeclarationTest.cs
  125. +9 −12 tests/ClangSharp.UnitTests/ModuleMapDescriptor.cs
  126. +8 −9 tests/ClangSharp.UnitTests/TranslationUnit.cs
  127. +18 −20 tests/ClangSharp.UnitTests/VirtualFileOverlay.cs
@@ -21,6 +21,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sources", "sources", "{732BA761-B58E-4C34-9C96-097382A55A7A}"
ProjectSection(SolutionItems) = preProject
sources\Directory.Build.props = sources\Directory.Build.props
sources\Directory.Build.targets = sources\Directory.Build.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClangSharp", "sources\ClangSharp\ClangSharp.csproj", "{A9D62BAC-5F38-4A37-8911-1F5952955C78}"
EndProject
@@ -29,6 +33,10 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClangSharpPInvokeGenerator", "sources\ClangSharpPInvokeGenerator\ClangSharpPInvokeGenerator.csproj", "{784B45C6-7A20-4F1C-A258-D81CDD9562A6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{394E17BB-B1EA-4A98-98C8-78ACD44182FC}"
ProjectSection(SolutionItems) = preProject
tests\Directory.Build.props = tests\Directory.Build.props
tests\Directory.Build.targets = tests\Directory.Build.targets
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClangSharp.UnitTests", "tests\ClangSharp.UnitTests\ClangSharp.UnitTests.csproj", "{4D0B43E1-921A-469F-A847-4473B2AF5172}"
EndProject
@@ -31,6 +31,7 @@
<PackageReference Update="Microsoft.Net.Compilers.Toolset" Version="3.2.0-beta1-final" />
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Update="System.CommandLine.Experimental" Version="0.2.0-alpha.19174.3" />
<PackageReference Update="System.Memory" Version="4.5.3" />
<PackageReference Update="xunit" Version="2.4.1" />
<PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
</ItemGroup>
@@ -1,9 +1,10 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace ClangSharp
{
internal class Cursor
internal unsafe class Cursor
{
public static Cursor Create(CXCursor handle, Cursor parent)
{
@@ -82,10 +83,9 @@ protected Cursor(CXCursor handle, Cursor parent)

public TranslationUnit TranslationUnit { get; }

public CXToken[] Tokenize(Cursor cursor)
public Span<CXToken> Tokenize(Cursor cursor)
{
Handle.TranslationUnit.Tokenize(cursor.Extent, out CXToken[] tokens);
return tokens;
return Handle.TranslationUnit.Tokenize(cursor.Extent);
}

public CXChildVisitResult Visit(CXClientData clientData)
@@ -149,6 +149,11 @@ protected virtual void ValidateVisit(ref CXCursor handle)
Debug.Assert(handle.Equals(Handle));
}

private unsafe CXChildVisitResult VisitChildren(CXCursor childHandle, CXCursor handle, void* clientData)
{
return VisitChildren(childHandle, handle, (CXClientData)clientData);
}

private CXChildVisitResult VisitChildren(CXCursor childHandle, CXCursor handle, CXClientData clientData)
{
ValidateVisit(ref handle);
@@ -164,12 +164,12 @@ protected Expr(CXCursor handle, Cursor parent) : base(handle, parent)

public Type Type { get; }

protected override void ValidateVisit(ref CXCursor handle)
protected unsafe override void ValidateVisit(ref CXCursor handle)
{
// Clang currently uses the PostChildrenVisitor which clears data0

var modifiedHandle = Handle;
modifiedHandle.data0 = IntPtr.Zero;
modifiedHandle.data[0] = null;

Debug.Assert(handle.Equals(modifiedHandle));
handle = Handle;
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics;

namespace ClangSharp
{
@@ -68,12 +67,12 @@ protected Stmt(CXCursor handle, Cursor parent) : base(handle, parent)
Debug.Assert(handle.IsStatement || (this is ValueStmt));
}

protected override void ValidateVisit(ref CXCursor handle)
protected unsafe override void ValidateVisit(ref CXCursor handle)
{
// Clang currently uses the PostChildrenVisitor which clears data0

var modifiedHandle = Handle;
modifiedHandle.data0 = IntPtr.Zero;
modifiedHandle.data[0] = null;

Debug.Assert(handle.Equals(modifiedHandle));
handle = Handle;
@@ -1,4 +1,4 @@
using System;
using System;

namespace ClangSharp
{

0 comments on commit 01e36c8

Please sign in to comment.
You can’t perform that action at this time.