generator generate doc comment

This commit is contained in:
neuecc 2023-04-16 00:36:08 +09:00
parent 6a60dc491a
commit 8809e01927
10 changed files with 77 additions and 47 deletions

View File

@ -2,6 +2,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml.Linq;
namespace GroupedNativeMethodsGenerator;
@ -102,11 +103,23 @@ using System.Runtime.InteropServices;
var ret = item.ReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var requireRet = ret == "void" ? "" : "return ";
string? summaryComment = null;
var docComment = item.GetDocumentationCommentXml();
if (!string.IsNullOrEmpty(docComment))
{
var xElem = XElement.Parse(docComment);
summaryComment = "/// " + xElem.Element("summary").ToString();
}
var convertedMethodName = ConvertMethodName(((IPointerTypeSymbol)firstArgument.Type).PointedAtType.Name, item.Name, removePrefix, removeSuffix, removeUntilTypeName, fixMethodName);
var pointedType = ((IPointerTypeSymbol)firstArgument.Type).PointedAtType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
var parameterPairs = string.Join("", item.Parameters.Skip(1).Select(x => $", {x.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)} @{x.Name}"));
var parameterNames = string.Join("", item.Parameters.Skip(1).Select(x => $", @{x.Name}"));
if (summaryComment != null)
{
code.AppendLine(" " + summaryComment);
}
code.AppendLine($" public static {ret} {convertedMethodName}(this ref {pointedType} @{firstArgument.Name}{parameterPairs})");
code.AppendLine(" {");
code.AppendLine($" {requireRet}{libTypeName}.{item.Name}(({pointedType}*)Unsafe.AsPointer(ref @{firstArgument.Name}){parameterNames});");

View File

@ -92,29 +92,29 @@ fn main() -> Result<(), Box<dyn Error>> {
.generate_csharp_file("../dotnet-sandbox/NativeMethods.cs")
.unwrap();
// csbindgen::Builder::new()
// .input_bindgen_file("src/zstd.rs")
// .method_filter(|x| x.starts_with("ZSTD_"))
// .rust_file_header("use super::zstd::*;")
// .csharp_class_name("LibZstd")
// .csharp_dll_name("libzsd")
// .generate_to_file("src/zstd_ffi.rs", "../dotnet-sandbox/zstd_bindgen.cs")?;
csbindgen::Builder::new()
.input_bindgen_file("src/zstd.rs")
.method_filter(|x| x.starts_with("ZSTD_"))
.rust_file_header("use super::zstd::*;")
.csharp_class_name("LibZstd")
.csharp_dll_name("libzsd")
.generate_to_file("src/zstd_ffi.rs", "../dotnet-sandbox/zstd_bindgen.cs")?;
// csbindgen::Builder::new()
// .input_bindgen_file("src/quiche.rs")
// .method_filter(|x| x.starts_with("quiche_"))
// .rust_file_header("use super::quiche::*;")
// .csharp_class_name("LibQuiche")
// .csharp_dll_name("libquiche")
// .generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs")?;
csbindgen::Builder::new()
.input_bindgen_file("src/quiche.rs")
.method_filter(|x| x.starts_with("quiche_"))
.rust_file_header("use super::quiche::*;")
.csharp_class_name("LibQuiche")
.csharp_dll_name("libquiche")
.generate_to_file("src/quiche_ffi.rs", "../dotnet-sandbox/quiche_bindgen.cs")?;
// csbindgen::Builder::new()
// .input_bindgen_file("src/bullet3.rs")
// .method_filter(|x| x.starts_with("b3"))
// .rust_file_header("use super::bullet3::*;")
// .csharp_class_name("LibBullet3")
// .csharp_dll_name("libbullet3")
// .generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
csbindgen::Builder::new()
.input_bindgen_file("src/bullet3.rs")
.method_filter(|x| x.starts_with("b3"))
.rust_file_header("use super::bullet3::*;")
.csharp_class_name("LibBullet3")
.csharp_dll_name("libbullet3")
.generate_to_file("src/bullet3_ffi.rs", "../dotnet-sandbox/bullet3_bindgen.cs")?;
csbindgen::Builder::new()

View File

@ -51,6 +51,7 @@ impl ExternMethod {
let ss = x
.trim_matches(&['=', ' ', '\"'] as &[_])
.replace("\\n", "")
.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;");
s.push_str(ss.as_str());

View File

@ -1,5 +1,8 @@

using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Physx
{
[GroupedNativeMethodsGenerator.GroupedNativeMethods(removePrefix: "Px")]
@ -24,6 +27,11 @@ namespace CsBindgen
public static unsafe partial class LibSqlite3
{
}
[GroupedNativeMethodsGenerator.GroupedNativeMethods()]
internal static unsafe partial class NativeMethods
{
}
}
@ -41,4 +49,17 @@ namespace Jolt
internal static unsafe partial class NativeMethods
{
}
}
namespace CsBindgen
{
internal static unsafe class NativeMethodsGroupingExtensions2
{
[DebuggerStepThrough]
public static void DeleteContext2(this ref global::CsBindgen.Context @context)
{
NativeMethods.delete_context((global::CsBindgen.Context*)Unsafe.AsPointer(ref @context));
}
}
}

View File

@ -3,6 +3,7 @@
// See https://aka.ms/new-console-template for more information
//using Csbindgen;
using CsBindgen;
using Physx;
using System.Buffers.Text;
using System.Reflection;
using System.Runtime.CompilerServices;
@ -12,29 +13,20 @@ using System.Text.RegularExpressions;
unsafe
{
// $vis:vis struct $BitFlags:ident: $T:ty {
// $(
// $(#[$inner:ident $($args:tt)*])*
// const $Flag:ident = $value:expr;
// )*
// }
//var foundation = LibPhysx.physx_create_foundation();
var foo = """
[doc = " Flags for [`PxRigidBodyFlag`]"] # [derive (Default)] # [repr (transparent)] pub struct PxRigidBodyFlags : u16 { const Kinematic = 1 << 0 ; const UseKinematicTargetForSceneQueries = 1 << 1; const EnableCcd = 1 << 2 ; const EnableCcdFriction = 1 << 3 ; const EnableSpeculativeCcd = 1 << 4 ; const EnablePoseIntegrationPreview = 1 << 5 ; const EnableCcdMaxContactImpulse = 1 << 6 ; const RetainAccelerations = 1 << 7 ; const ForceKineKineNotifications = 1 << 8 ; const ForceStaticKineNotifications = 1 << 9 ; const EnableGyroscopicForces = 1 << 10 ; }
"""
;
//foundation->ReleaseMut();
var match1 = Regex.Match(foo, "pub struct ([^ ]+) : ([^ ]+) {");
var enum_name = match1.Groups[1].Value;
var enum_type = match1.Groups[2].Value;
var match2 = Regex.Matches(foo, "const ([^ ]+) = ([^;]+)[ ]*;");
//var vec3 = new PxVec3() { x = 10.0f };
var ctx = NativeMethods.create_context();
ctx->DeleteContext2();
//NativeMethods.call_bindgen_lz4();

View File

@ -2,6 +2,7 @@
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#pragma warning disable CS8500
#pragma warning disable CS8981
using System;
using System.Runtime.InteropServices;

View File

@ -5225,7 +5225,7 @@ namespace Physx
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool PxScene_resetFiltering_mut(PxScene* self_, PxActor* actor);
/// <summary>Marks the object to reset interactions and re-run collision filters for specified shapes in the next simulation step. This is a specialization of the resetFiltering(PxActor & actor) method and allows to reset interactions for specific shapes of a PxRigidActor. Do not use this method while the simulation is running. Sleeping: Does wake up the actor.</summary>
/// <summary>Marks the object to reset interactions and re-run collision filters for specified shapes in the next simulation step. This is a specialization of the resetFiltering(PxActor &amp; actor) method and allows to reset interactions for specific shapes of a PxRigidActor. Do not use this method while the simulation is running. Sleeping: Does wake up the actor.</summary>
[DllImport(__DllName, EntryPoint = "PxScene_resetFiltering_mut_1", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool PxScene_resetFiltering_mut_1(PxScene* self_, PxRigidActor* actor, PxShape** shapes, uint shapeCount);
@ -6382,7 +6382,7 @@ namespace Physx
[DllImport(__DllName, EntryPoint = "PxSpring_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PxSpring PxSpring_new(float stiffness_, float damping_);
/// <summary>Helper function to setup a joint's global frame This replaces the following functions from previous SDK versions: void NxJointDesc::setGlobalAnchor(const NxVec3 & wsAnchor); void NxJointDesc::setGlobalAxis(const NxVec3 & wsAxis); The function sets the joint's localPose using world-space input parameters.</summary>
/// <summary>Helper function to setup a joint's global frame This replaces the following functions from previous SDK versions: void NxJointDesc::setGlobalAnchor(const NxVec3 &amp; wsAnchor); void NxJointDesc::setGlobalAxis(const NxVec3 &amp; wsAxis); The function sets the joint's localPose using world-space input parameters.</summary>
[DllImport(__DllName, EntryPoint = "phys_PxSetJointGlobalFrame", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void phys_PxSetJointGlobalFrame(PxJoint* joint, PxVec3* wsAnchor, PxVec3* wsAxis);
@ -6434,7 +6434,7 @@ namespace Physx
[DllImport(__DllName, EntryPoint = "PxDistanceJoint_getDamping", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern float PxDistanceJoint_getDamping(PxDistanceJoint* self_);
/// <summary>Set the contact distance for the min & max distance limits. This is similar to the PxJointLimitParameters::contactDistance parameter for regular limits. The two most common values are 0 and infinite. Infinite means the internal constraints are always created, resulting in the best simulation quality but slower performance. Zero means the internal constraints are only created when the limits are violated, resulting in best performance but worse simulation quality. Default 0.0f Range [0, PX_MAX_F32)</summary>
/// <summary>Set the contact distance for the min &amp; max distance limits. This is similar to the PxJointLimitParameters::contactDistance parameter for regular limits. The two most common values are 0 and infinite. Infinite means the internal constraints are always created, resulting in the best simulation quality but slower performance. Zero means the internal constraints are only created when the limits are violated, resulting in best performance but worse simulation quality. Default 0.0f Range [0, PX_MAX_F32)</summary>
[DllImport(__DllName, EntryPoint = "PxDistanceJoint_setContactDistance_mut", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void PxDistanceJoint_setContactDistance_mut(PxDistanceJoint* self_, float contactDistance);
@ -6887,11 +6887,11 @@ namespace Physx
[DllImport(__DllName, EntryPoint = "PxGearJoint_getConcreteTypeName", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern byte* PxGearJoint_getConcreteTypeName(PxGearJoint* self_);
/// <summary>Create a rack & pinion Joint.</summary>
/// <summary>Create a rack &amp; pinion Joint.</summary>
[DllImport(__DllName, EntryPoint = "phys_PxRackAndPinionJointCreate", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PxRackAndPinionJoint* phys_PxRackAndPinionJointCreate(PxPhysics* physics, PxRigidActor* actor0, PxTransform* localFrame0, PxRigidActor* actor1, PxTransform* localFrame1);
/// <summary>Set the hinge & prismatic joints connected by the rack & pinion joint. The passed hinge joint can be either PxRevoluteJoint, PxD6Joint or PxArticulationJointReducedCoordinate. It cannot be null. The passed prismatic joint can be either PxPrismaticJoint or PxD6Joint. It cannot be null. Note that these joints are only used to compute the positional error correction term, used to adjust potential drift between jointed actors. The rack & pinion joint can run without calling this function, but in that case some visible overlap may develop over time between the teeth of the rack & pinion meshes. Calling this function resets the internal positional error correction term. true if success</summary>
/// <summary>Set the hinge &amp; prismatic joints connected by the rack &amp; pinion joint. The passed hinge joint can be either PxRevoluteJoint, PxD6Joint or PxArticulationJointReducedCoordinate. It cannot be null. The passed prismatic joint can be either PxPrismaticJoint or PxD6Joint. It cannot be null. Note that these joints are only used to compute the positional error correction term, used to adjust potential drift between jointed actors. The rack &amp; pinion joint can run without calling this function, but in that case some visible overlap may develop over time between the teeth of the rack &amp; pinion meshes. Calling this function resets the internal positional error correction term. true if success</summary>
[DllImport(__DllName, EntryPoint = "PxRackAndPinionJoint_setJoints_mut", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool PxRackAndPinionJoint_setJoints_mut(PxRackAndPinionJoint* self_, PxBase* hinge, PxBase* prismatic);
@ -6993,7 +6993,7 @@ namespace Physx
[DllImport(__DllName, EntryPoint = "PxRigidActorExt_getRigidActorShapeLocalBoundsList", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PxBounds3* PxRigidActorExt_getRigidActorShapeLocalBoundsList(PxRigidActor* actor, uint* numBounds);
/// <summary>Convenience function to create a PxBVH object from a PxRigidActor. The computed PxBVH can then be used in PxScene::addActor() or PxAggregate::addActor(). After adding the actor & BVH to the scene/aggregate, release the PxBVH object by calling PxBVH::release(). The PxBVH for this actor.</summary>
/// <summary>Convenience function to create a PxBVH object from a PxRigidActor. The computed PxBVH can then be used in PxScene::addActor() or PxAggregate::addActor(). After adding the actor &amp; BVH to the scene/aggregate, release the PxBVH object by calling PxBVH::release(). The PxBVH for this actor.</summary>
[DllImport(__DllName, EntryPoint = "PxRigidActorExt_createBVHFromActor", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern PxBVH* PxRigidActorExt_createBVHFromActor(PxPhysics* physics, PxRigidActor* actor);
@ -7345,7 +7345,7 @@ namespace Physx
[DllImport(__DllName, EntryPoint = "PxCustomSceneQuerySystem_addPruner_mut", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint PxCustomSceneQuerySystem_addPruner_mut(PxCustomSceneQuerySystem* self_, PxPruningStructureType primaryType, PxDynamicTreeSecondaryPruner secondaryType, uint preallocated);
/// <summary>Start custom build-steps for all pruners This function is used in combination with customBuildstep() and finishCustomBuildstep() to let users take control of the pruners' build-step & commit calls - basically the pruners' update functions. These functions should be used with the PxSceneQueryUpdateMode::eBUILD_DISABLED_COMMIT_DISABLED update mode, otherwise the build-steps will happen automatically in fetchResults. For N pruners it can be more efficient to use these custom build-step functions to perform the updates in parallel: - call startCustomBuildstep() first (one synchronous call) - for each pruner, call customBuildstep() (asynchronous calls from multiple threads) - once it is done, call finishCustomBuildstep() to finish the update (synchronous call) The multi-threaded update is more efficient here than what it is in PxScene, because the \"flushShapes()\" call is also multi-threaded (while it is not in PxScene). Note that users are responsible for locks here, and these calls should not overlap with other SQ calls. In particular one should not add new objects to the SQ system or perform queries while these calls are happening. The number of pruners in the system.</summary>
/// <summary>Start custom build-steps for all pruners This function is used in combination with customBuildstep() and finishCustomBuildstep() to let users take control of the pruners' build-step &amp; commit calls - basically the pruners' update functions. These functions should be used with the PxSceneQueryUpdateMode::eBUILD_DISABLED_COMMIT_DISABLED update mode, otherwise the build-steps will happen automatically in fetchResults. For N pruners it can be more efficient to use these custom build-step functions to perform the updates in parallel: - call startCustomBuildstep() first (one synchronous call) - for each pruner, call customBuildstep() (asynchronous calls from multiple threads) - once it is done, call finishCustomBuildstep() to finish the update (synchronous call) The multi-threaded update is more efficient here than what it is in PxScene, because the \"flushShapes()\" call is also multi-threaded (while it is not in PxScene). Note that users are responsible for locks here, and these calls should not overlap with other SQ calls. In particular one should not add new objects to the SQ system or perform queries while these calls are happening. The number of pruners in the system.</summary>
[DllImport(__DllName, EntryPoint = "PxCustomSceneQuerySystem_startCustomBuildstep_mut", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern uint PxCustomSceneQuerySystem_startCustomBuildstep_mut(PxCustomSceneQuerySystem* self_);

View File

@ -91,7 +91,7 @@ namespace CsBindgen
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_decoderRingBufferSize", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int LZ4_decoderRingBufferSize(int maxBlockSize);
/// <summary>LZ4_decompress_safe_continue() : This decoding function allows decompression of consecutive blocks in \"streaming\" mode. The difference with the usual independent blocks is that new blocks are allowed to find references into former blocks. A block is an unsplittable entity, and must be presented entirely to the decompression function. LZ4_decompress_safe_continue() only accepts one block at a time. It's modeled after `LZ4_decompress_safe()` and behaves similarly. @LZ4_streamDecode : decompression state, tracking the position in memory of past data @compressedSize : exact complete size of one compressed block. @dstCapacity : size of destination buffer (which must be already allocated), must be an upper bound of decompressed size. @return : number of bytes decompressed into destination buffer (necessarily &lt;= dstCapacity) If destination buffer is not large enough, decoding will stop and output an error code (negative value). If the source stream is detected malformed, the function will stop decoding and return a negative result. The last 64KB of previously decoded data *must* remain available and unmodified at the memory position where they were previously decoded. If less than 64KB of data has been decoded, all the data must be present. Special : if decompression side sets a ring buffer, it must respect one of the following conditions : - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize). maxBlockSize is the maximum size of any single block. It can have any value &gt; 16 bytes. In which case, encoding and decoding buffers do not need to be synchronized. Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize. - Synchronized mode : Decompression buffer size is _exactly_ the same as compression buffer size, and follows exactly same update rule (block boundaries at same positions), and decoding function is provided with exact decompressed size of each block (exception for last block of the stream), _then_ decoding & encoding ring buffer can have any size, including small ones ( &lt; 64 KB). - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes. In which case, encoding and decoding buffers do not need to be synchronized, and encoding ring buffer can have any size, including small ones ( &lt; 64 KB). Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression, then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.</summary>
/// <summary>LZ4_decompress_safe_continue() : This decoding function allows decompression of consecutive blocks in \"streaming\" mode. The difference with the usual independent blocks is that new blocks are allowed to find references into former blocks. A block is an unsplittable entity, and must be presented entirely to the decompression function. LZ4_decompress_safe_continue() only accepts one block at a time. It's modeled after `LZ4_decompress_safe()` and behaves similarly. @LZ4_streamDecode : decompression state, tracking the position in memory of past data @compressedSize : exact complete size of one compressed block. @dstCapacity : size of destination buffer (which must be already allocated), must be an upper bound of decompressed size. @return : number of bytes decompressed into destination buffer (necessarily &lt;= dstCapacity) If destination buffer is not large enough, decoding will stop and output an error code (negative value). If the source stream is detected malformed, the function will stop decoding and return a negative result. The last 64KB of previously decoded data *must* remain available and unmodified at the memory position where they were previously decoded. If less than 64KB of data has been decoded, all the data must be present. Special : if decompression side sets a ring buffer, it must respect one of the following conditions : - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize). maxBlockSize is the maximum size of any single block. It can have any value &gt; 16 bytes. In which case, encoding and decoding buffers do not need to be synchronized. Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize. - Synchronized mode : Decompression buffer size is _exactly_ the same as compression buffer size, and follows exactly same update rule (block boundaries at same positions), and decoding function is provided with exact decompressed size of each block (exception for last block of the stream), _then_ decoding &amp; encoding ring buffer can have any size, including small ones ( &lt; 64 KB). - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes. In which case, encoding and decoding buffers do not need to be synchronized, and encoding ring buffer can have any size, including small ones ( &lt; 64 KB). Whenever these conditions are not possible, save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression, then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.</summary>
[DllImport(__DllName, EntryPoint = "csbindgen_LZ4_decompress_safe_continue", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int LZ4_decompress_safe_continue(LZ4_streamDecode_u* LZ4_streamDecode, byte* src, byte* dst, int srcSize, int dstCapacity);

View File

@ -2,6 +2,7 @@
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#pragma warning disable CS8500
#pragma warning disable CS8981
using System;
using System.Runtime.InteropServices;

View File

@ -2,6 +2,7 @@
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#pragma warning disable CS8500
#pragma warning disable CS8981
using System;
using System.Runtime.InteropServices;
@ -133,11 +134,11 @@ namespace CsBindgen
[DllImport(__DllName, EntryPoint = "ZSTD_compressStream", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint ZSTD_compressStream(ZSTD_CCtx_s* zcs, ZSTD_outBuffer_s* output, ZSTD_inBuffer_s* input);
/// <summary>Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_flush).</summary>
/// <summary>Equivalent to ZSTD_compressStream2(zcs, output, &amp;emptyInput, ZSTD_e_flush).</summary>
[DllImport(__DllName, EntryPoint = "ZSTD_flushStream", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint ZSTD_flushStream(ZSTD_CCtx_s* zcs, ZSTD_outBuffer_s* output);
/// <summary>Equivalent to ZSTD_compressStream2(zcs, output, &emptyInput, ZSTD_e_end).</summary>
/// <summary>Equivalent to ZSTD_compressStream2(zcs, output, &amp;emptyInput, ZSTD_e_end).</summary>
[DllImport(__DllName, EntryPoint = "ZSTD_endStream", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern nuint ZSTD_endStream(ZSTD_CCtx_s* zcs, ZSTD_outBuffer_s* output);