From 5fad7aedeba73aa46d5efa355588202c99f66807 Mon Sep 17 00:00:00 2001 From: Laura Hermanns Date: Thu, 10 Aug 2023 21:25:34 -0400 Subject: [PATCH] Continued with wrapper generator. --- include/LLGL-C/LLGLWrapper.h | 234 ++++++++++---------- scripts/GenerateWrappers.bat | 39 +++- scripts/ParseLLGLHeader.py | 412 ++++++++++++++++++++++++----------- 3 files changed, 434 insertions(+), 251 deletions(-) diff --git a/include/LLGL-C/LLGLWrapper.h b/include/LLGL-C/LLGLWrapper.h index 6fdc3a0000..16bbbbdf45 100644 --- a/include/LLGL-C/LLGLWrapper.h +++ b/include/LLGL-C/LLGLWrapper.h @@ -11,9 +11,9 @@ #define LLGL_C99_LLGLWRAPPER_H -#include #include #include +#include #include #if defined LLGL_OS_ANDROID @@ -981,8 +981,8 @@ LLGLDepthBiasDescriptor; typedef struct LLGLComputePipelineDescriptor { - LLGLPipelineLayout pipelineLayout; /* = nullptr */ - LLGLShader computeShader; /* = nullptr */ + LLGLPipelineLayout pipelineLayout; /* = LLGL_NULL_OBJECT */ + LLGLShader computeShader; /* = LLGL_NULL_OBJECT */ } LLGLComputePipelineDescriptor; @@ -1008,8 +1008,8 @@ typedef struct LLGLRendererInfo const char* deviceName; const char* vendorName; const char* shadingLanguageName; - size_t numExtensionNames; - const char* const* extensionNames; + size_t numExtensionNames; /* = 0 */ + const char* const* extensionNames; /* = NULL */ } LLGLRendererInfo; @@ -1076,7 +1076,7 @@ LLGLRenderingLimits; typedef struct LLGLResourceHeapDescriptor { - LLGLPipelineLayout pipelineLayout; /* = nullptr */ + LLGLPipelineLayout pipelineLayout; /* = LLGL_NULL_OBJECT */ uint32_t numResourceViews; /* = 0 */ long barrierFlags; /* = 0 */ } @@ -1084,8 +1084,8 @@ LLGLResourceHeapDescriptor; typedef struct LLGLShaderMacro { - const char* name; /* = nullptr */ - const char* definition; /* = nullptr */ + const char* name; /* = NULL */ + const char* definition; /* = NULL */ } LLGLShaderMacro; @@ -1142,15 +1142,15 @@ LLGLOffset3D; typedef struct LLGLWindowBehavior { bool disableClearOnResize; /* = false */ - uint32_t moveAndResizeTimerID; /* = Constants::invalidTimerID */ + uint32_t moveAndResizeTimerID; /* = LLGLConstantsinvalidTimerID */ } LLGLWindowBehavior; typedef struct LLGLBufferViewDescriptor { - LLGLFormat format; /* = Format::Undefined */ + LLGLFormat format; /* = LLGLFormatUndefined */ uint64_t offset; /* = 0 */ - uint64_t size; /* = Constants::wholeSize */ + uint64_t size; /* = LLGLConstantswholeSize */ } LLGLBufferViewDescriptor; @@ -1184,26 +1184,26 @@ LLGLFormatAttributes; typedef struct LLGLFragmentAttribute { const char* name; - LLGLFormat format; /* = Format::RGBA32Float */ + LLGLFormat format; /* = LLGLFormatRGBA32Float */ uint32_t location; /* = 0 */ - LLGLSystemValue systemValue; /* = SystemValue::Undefined */ + LLGLSystemValue systemValue; /* = LLGLSystemValueUndefined */ } LLGLFragmentAttribute; typedef struct LLGLSrcImageDescriptor { - LLGLImageFormat format; /* = ImageFormat::RGBA */ - LLGLDataType dataType; /* = DataType::UInt8 */ - const void* data; /* = nullptr */ + LLGLImageFormat format; /* = LLGLImageFormatRGBA */ + LLGLDataType dataType; /* = LLGLDataTypeUInt8 */ + const void* data; /* = NULL */ size_t dataSize; /* = 0 */ } LLGLSrcImageDescriptor; typedef struct LLGLDstImageDescriptor { - LLGLImageFormat format; /* = ImageFormat::RGBA */ - LLGLDataType dataType; /* = DataType::UInt8 */ - void* data; /* = nullptr */ + LLGLImageFormat format; /* = LLGLImageFormatRGBA */ + LLGLDataType dataType; /* = LLGLDataTypeUInt8 */ + void* data; /* = NULL */ size_t dataSize; /* = 0 */ } LLGLDstImageDescriptor; @@ -1211,7 +1211,7 @@ LLGLDstImageDescriptor; typedef struct LLGLBindingDescriptor { const char* name; - LLGLResourceType type; /* = ResourceType::Undefined */ + LLGLResourceType type; /* = LLGLResourceTypeUndefined */ long bindFlags; /* = 0 */ long stageFlags; /* = 0 */ LLGLBindingSlot slot; @@ -1222,7 +1222,7 @@ LLGLBindingDescriptor; typedef struct LLGLUniformDescriptor { const char* name; - LLGLUniformType type; /* = UniformType::Undefined */ + LLGLUniformType type; /* = LLGLUniformTypeUndefined */ uint32_t arraySize; /* = 0 */ } LLGLUniformDescriptor; @@ -1231,16 +1231,16 @@ typedef struct LLGLDepthDescriptor { bool testEnabled; /* = false */ bool writeEnabled; /* = false */ - LLGLCompareOp compareOp; /* = CompareOp::Less */ + LLGLCompareOp compareOp; /* = LLGLCompareOpLess */ } LLGLDepthDescriptor; typedef struct LLGLStencilFaceDescriptor { - LLGLStencilOp stencilFailOp; /* = StencilOp::Keep */ - LLGLStencilOp depthFailOp; /* = StencilOp::Keep */ - LLGLStencilOp depthPassOp; /* = StencilOp::Keep */ - LLGLCompareOp compareOp; /* = CompareOp::Less */ + LLGLStencilOp stencilFailOp; /* = LLGLStencilOpKeep */ + LLGLStencilOp depthFailOp; /* = LLGLStencilOpKeep */ + LLGLStencilOp depthPassOp; /* = LLGLStencilOpKeep */ + LLGLCompareOp compareOp; /* = LLGLCompareOpLess */ uint32_t readMask; /* = 0u */ uint32_t writeMask; /* = 0u */ uint32_t reference; /* = 0u */ @@ -1249,8 +1249,8 @@ LLGLStencilFaceDescriptor; typedef struct LLGLRasterizerDescriptor { - LLGLPolygonMode polygonMode; /* = PolygonMode::Fill */ - LLGLCullMode cullMode; /* = CullMode::Disabled */ + LLGLPolygonMode polygonMode; /* = LLGLPolygonModeFill */ + LLGLCullMode cullMode; /* = LLGLCullModeDisabled */ LLGLDepthBiasDescriptor depthBias; bool frontCCW; /* = false */ bool discardEnabled; /* = false */ @@ -1266,20 +1266,20 @@ LLGLRasterizerDescriptor; typedef struct LLGLBlendTargetDescriptor { bool blendEnabled; /* = false */ - LLGLBlendOp srcColor; /* = BlendOp::SrcAlpha */ - LLGLBlendOp dstColor; /* = BlendOp::InvSrcAlpha */ - LLGLBlendArithmetic colorArithmetic; /* = BlendArithmetic::Add */ - LLGLBlendOp srcAlpha; /* = BlendOp::SrcAlpha */ - LLGLBlendOp dstAlpha; /* = BlendOp::InvSrcAlpha */ - LLGLBlendArithmetic alphaArithmetic; /* = BlendArithmetic::Add */ - uint8_t colorMask; /* = ColorMaskFlags::All */ + LLGLBlendOp srcColor; /* = LLGLBlendOpSrcAlpha */ + LLGLBlendOp dstColor; /* = LLGLBlendOpInvSrcAlpha */ + LLGLBlendArithmetic colorArithmetic; /* = LLGLBlendArithmeticAdd */ + LLGLBlendOp srcAlpha; /* = LLGLBlendOpSrcAlpha */ + LLGLBlendOp dstAlpha; /* = LLGLBlendOpInvSrcAlpha */ + LLGLBlendArithmetic alphaArithmetic; /* = LLGLBlendArithmeticAdd */ + uint8_t colorMask; /* = LLGLColorMaskAll */ } LLGLBlendTargetDescriptor; typedef struct LLGLTessellationDescriptor { - LLGLTessellationPartition partition; /* = TessellationPartition::Undefined */ - LLGLFormat indexFormat; /* = Format::Undefined */ + LLGLTessellationPartition partition; /* = LLGLTessellationPartitionUndefined */ + LLGLFormat indexFormat; /* = LLGLFormatUndefined */ uint32_t maxTessFactor; /* = 64 */ bool outputWindingCCW; /* = false */ } @@ -1287,7 +1287,7 @@ LLGLTessellationDescriptor; typedef struct LLGLQueryHeapDescriptor { - LLGLQueryType type; /* = QueryType::SamplesPassed */ + LLGLQueryType type; /* = LLGLQueryTypeSamplesPassed */ uint32_t numQueries; /* = 1 */ bool renderCondition; /* = false */ } @@ -1295,9 +1295,9 @@ LLGLQueryHeapDescriptor; typedef struct LLGLAttachmentFormatDescriptor { - LLGLFormat format; /* = Format::Undefined */ - LLGLAttachmentLoadOp loadOp; /* = AttachmentLoadOp::Undefined */ - LLGLAttachmentStoreOp storeOp; /* = AttachmentStoreOp::Undefined */ + LLGLFormat format; /* = LLGLFormatUndefined */ + LLGLAttachmentLoadOp loadOp; /* = LLGLAttachmentLoadOpUndefined */ + LLGLAttachmentStoreOp storeOp; /* = LLGLAttachmentStoreOpUndefined */ } LLGLAttachmentFormatDescriptor; @@ -1305,24 +1305,24 @@ typedef struct LLGLRenderSystemDescriptor { const char* moduleName; long flags; /* = 0 */ - LLGLRenderingProfiler profiler; /* = nullptr */ - LLGLRenderingDebugger debugger; /* = nullptr */ - const void* rendererConfig; /* = nullptr */ + LLGLRenderingProfiler profiler; /* = LLGL_NULL_OBJECT */ + LLGLRenderingDebugger debugger; /* = LLGL_NULL_OBJECT */ + const void* rendererConfig; /* = NULL */ size_t rendererConfigSize; /* = 0 */ - #if defined LLGL_OS_ANDROID +#if defined LLGL_OS_ANDROID android_app* androidApp; - #endif /* defined LLGL_OS_ANDROID */ +#endif /* defined LLGL_OS_ANDROID */ } LLGLRenderSystemDescriptor; typedef struct LLGLRenderingCapabilities { - LLGLScreenOrigin screenOrigin; /* = ScreenOrigin::UpperLeft */ - LLGLClippingRange clippingRange; /* = ClippingRange::ZeroToOne */ - size_t numShadingLanguages; - const LLGLShadingLanguage* shadingLanguages; - size_t numTextureFormats; - const LLGLFormat* textureFormats; + LLGLScreenOrigin screenOrigin; /* = LLGLScreenOriginUpperLeft */ + LLGLClippingRange clippingRange; /* = LLGLClippingRangeZeroToOne */ + size_t numShadingLanguages; /* = 0 */ + const LLGLShadingLanguage* shadingLanguages; /* = NULL */ + size_t numTextureFormats; /* = 0 */ + const LLGLFormat* textureFormats; /* = NULL */ LLGLRenderingFeatures features; LLGLRenderingLimits limits; } @@ -1330,8 +1330,8 @@ LLGLRenderingCapabilities; typedef struct LLGLAttachmentDescriptor { - LLGLFormat format; /* = Format::Undefined */ - LLGLTexture texture; /* = nullptr */ + LLGLFormat format; /* = LLGLFormatUndefined */ + LLGLTexture texture; /* = LLGL_NULL_OBJECT */ uint32_t mipLevel; /* = 0 */ uint32_t arrayLayer; /* = 0 */ } @@ -1339,19 +1339,19 @@ LLGLAttachmentDescriptor; typedef struct LLGLSamplerDescriptor { - LLGLSamplerAddressMode addressModeU; /* = SamplerAddressMode::Repeat */ - LLGLSamplerAddressMode addressModeV; /* = SamplerAddressMode::Repeat */ - LLGLSamplerAddressMode addressModeW; /* = SamplerAddressMode::Repeat */ - LLGLSamplerFilter minFilter; /* = SamplerFilter::Linear */ - LLGLSamplerFilter magFilter; /* = SamplerFilter::Linear */ - LLGLSamplerFilter mipMapFilter; /* = SamplerFilter::Linear */ + LLGLSamplerAddressMode addressModeU; /* = LLGLSamplerAddressModeRepeat */ + LLGLSamplerAddressMode addressModeV; /* = LLGLSamplerAddressModeRepeat */ + LLGLSamplerAddressMode addressModeW; /* = LLGLSamplerAddressModeRepeat */ + LLGLSamplerFilter minFilter; /* = LLGLSamplerFilterLinear */ + LLGLSamplerFilter magFilter; /* = LLGLSamplerFilterLinear */ + LLGLSamplerFilter mipMapFilter; /* = LLGLSamplerFilterLinear */ bool mipMapEnabled; /* = true */ float mipMapLODBias; /* = 0.0f */ float minLOD; /* = 0.0f */ float maxLOD; /* = 1000.0f */ uint32_t maxAnisotropy; /* = 1 */ bool compareEnabled; /* = false */ - LLGLCompareOp compareOp; /* = CompareOp::Less */ + LLGLCompareOp compareOp; /* = LLGLCompareOpLess */ float borderColor[4]; /* = {0.0f,0.0f,0.0f,0.0f} */ } LLGLSamplerDescriptor; @@ -1376,10 +1376,10 @@ LLGLSwapChainDescriptor; typedef struct LLGLTextureSwizzleRGBA { - LLGLTextureSwizzle r : 8; /* = TextureSwizzle::Red */ - LLGLTextureSwizzle g : 8; /* = TextureSwizzle::Green */ - LLGLTextureSwizzle b : 8; /* = TextureSwizzle::Blue */ - LLGLTextureSwizzle a : 8; /* = TextureSwizzle::Alpha */ + LLGLTextureSwizzle r : 8; /* = LLGLTextureSwizzleRed */ + LLGLTextureSwizzle g : 8; /* = LLGLTextureSwizzleGreen */ + LLGLTextureSwizzle b : 8; /* = LLGLTextureSwizzleBlue */ + LLGLTextureSwizzle a : 8; /* = LLGLTextureSwizzleAlpha */ } LLGLTextureSwizzleRGBA; @@ -1401,10 +1401,10 @@ LLGLTextureRegion; typedef struct LLGLTextureDescriptor { - LLGLTextureType type; /* = TextureType::Texture2D */ - long bindFlags; /* = (BindFlags::Sampled|BindFlags::ColorAttachment) */ - long miscFlags; /* = (MiscFlags::FixedSamples|MiscFlags::GenerateMips) */ - LLGLFormat format; /* = Format::RGBA8UNorm */ + LLGLTextureType type; /* = LLGLTextureTypeTexture2D */ + long bindFlags; /* = (LLGLBindSampled | LLGLBindColorAttachment) */ + long miscFlags; /* = (LLGLMiscFixedSamples | LLGLMiscGenerateMips) */ + LLGLFormat format; /* = LLGLFormatRGBA8UNorm */ LLGLExtent3D extent; /* = {1,1,1} */ uint32_t arrayLayers; /* = 1 */ uint32_t mipLevels; /* = 0 */ @@ -1416,10 +1416,10 @@ LLGLTextureDescriptor; typedef struct LLGLVertexAttribute { const char* name; - LLGLFormat format; /* = Format::RGBA32Float */ + LLGLFormat format; /* = LLGLFormatRGBA32Float */ uint32_t location; /* = 0 */ uint32_t semanticIndex; /* = 0 */ - LLGLSystemValue systemValue; /* = SystemValue::Undefined */ + LLGLSystemValue systemValue; /* = LLGLSystemValueUndefined */ uint32_t slot; /* = 0 */ uint32_t offset; /* = 0 */ uint32_t stride; /* = 0 */ @@ -1437,7 +1437,7 @@ typedef struct LLGLWindowDescriptor bool resizable; /* = false */ bool acceptDropFiles; /* = false */ bool centered; /* = false */ - const void* windowContext; /* = nullptr */ + const void* windowContext; /* = NULL */ } LLGLWindowDescriptor; @@ -1445,12 +1445,12 @@ typedef struct LLGLBufferDescriptor { uint64_t size; /* = 0 */ uint32_t stride; /* = 0 */ - LLGLFormat format; /* = Format::Undefined */ + LLGLFormat format; /* = LLGLFormatUndefined */ long bindFlags; /* = 0 */ long cpuAccessFlags; /* = 0 */ long miscFlags; /* = 0 */ - size_t numVertexAttribs; - const LLGLVertexAttribute* vertexAttribs; + size_t numVertexAttribs; /* = 0 */ + const LLGLVertexAttribute* vertexAttribs; /* = NULL */ } LLGLBufferDescriptor; @@ -1477,7 +1477,7 @@ typedef struct LLGLBlendDescriptor bool alphaToCoverageEnabled; /* = false */ bool independentBlendEnabled; /* = false */ uint32_t sampleMask; /* = 0u */ - LLGLLogicOp logicOp; /* = LogicOp::Disabled */ + LLGLLogicOp logicOp; /* = LLGLLogicOpDisabled */ float blendFactor[4]; /* = {0.0f,0.0f,0.0f,0.0f} */ bool blendFactorDynamic; /* = false */ LLGLBlendTargetDescriptor targets[8]; @@ -1495,7 +1495,7 @@ LLGLRenderPassDescriptor; typedef struct LLGLRenderTargetDescriptor { - LLGLRenderPass renderPass; /* = nullptr */ + LLGLRenderPass renderPass; /* = LLGL_NULL_OBJECT */ LLGLExtent2D resolution; uint32_t samples; /* = 1 */ LLGLAttachmentDescriptor colorAttachments[8]; @@ -1506,17 +1506,17 @@ LLGLRenderTargetDescriptor; typedef struct LLGLVertexShaderAttributes { - size_t numInputAttribs; - const LLGLVertexAttribute* inputAttribs; - size_t numOutputAttribs; - const LLGLVertexAttribute* outputAttribs; + size_t numInputAttribs; /* = 0 */ + const LLGLVertexAttribute* inputAttribs; /* = NULL */ + size_t numOutputAttribs; /* = 0 */ + const LLGLVertexAttribute* outputAttribs; /* = NULL */ } LLGLVertexShaderAttributes; typedef struct LLGLFragmentShaderAttributes { - size_t numOutputAttribs; - const LLGLFragmentAttribute* outputAttribs; + size_t numOutputAttribs; /* = 0 */ + const LLGLFragmentAttribute* outputAttribs; /* = NULL */ } LLGLFragmentShaderAttributes; @@ -1524,14 +1524,14 @@ typedef struct LLGLShaderResourceReflection { LLGLBindingDescriptor binding; uint32_t constantBufferSize; /* = 0 */ - LLGLStorageBufferType storageBufferType; /* = StorageBufferType::Undefined */ + LLGLStorageBufferType storageBufferType; /* = LLGLStorageBufferTypeUndefined */ } LLGLShaderResourceReflection; typedef struct LLGLTextureViewDescriptor { - LLGLTextureType type; /* = TextureType::Texture2D */ - LLGLFormat format; /* = Format::RGBA8UNorm */ + LLGLTextureType type; /* = LLGLTextureTypeTexture2D */ + LLGLFormat format; /* = LLGLFormatRGBA8UNorm */ LLGLTextureSubresource subresource; LLGLTextureSwizzleRGBA swizzle; } @@ -1539,31 +1539,31 @@ LLGLTextureViewDescriptor; typedef struct LLGLPipelineLayoutDescriptor { - size_t numHeapBindings; - const LLGLBindingDescriptor* heapBindings; - size_t numBindings; - const LLGLBindingDescriptor* bindings; - size_t numStaticSamplers; - const LLGLStaticSamplerDescriptor* staticSamplers; - size_t numUniforms; - const LLGLUniformDescriptor* uniforms; + size_t numHeapBindings; /* = 0 */ + const LLGLBindingDescriptor* heapBindings; /* = NULL */ + size_t numBindings; /* = 0 */ + const LLGLBindingDescriptor* bindings; /* = NULL */ + size_t numStaticSamplers; /* = 0 */ + const LLGLStaticSamplerDescriptor* staticSamplers; /* = NULL */ + size_t numUniforms; /* = 0 */ + const LLGLUniformDescriptor* uniforms; /* = NULL */ } LLGLPipelineLayoutDescriptor; typedef struct LLGLGraphicsPipelineDescriptor { - LLGLPipelineLayout pipelineLayout; /* = nullptr */ - LLGLRenderPass renderPass; /* = nullptr */ - LLGLShader vertexShader; /* = nullptr */ - LLGLShader tessControlShader; /* = nullptr */ - LLGLShader tessEvaluationShader; /* = nullptr */ - LLGLShader geometryShader; /* = nullptr */ - LLGLShader fragmentShader; /* = nullptr */ - LLGLPrimitiveTopology primitiveTopology; /* = PrimitiveTopology::TriangleList */ - size_t numViewports; - const LLGLViewport* viewports; - size_t numScissors; - const LLGLScissor* scissors; + LLGLPipelineLayout pipelineLayout; /* = LLGL_NULL_OBJECT */ + LLGLRenderPass renderPass; /* = LLGL_NULL_OBJECT */ + LLGLShader vertexShader; /* = LLGL_NULL_OBJECT */ + LLGLShader tessControlShader; /* = LLGL_NULL_OBJECT */ + LLGLShader tessEvaluationShader; /* = LLGL_NULL_OBJECT */ + LLGLShader geometryShader; /* = LLGL_NULL_OBJECT */ + LLGLShader fragmentShader; /* = LLGL_NULL_OBJECT */ + LLGLPrimitiveTopology primitiveTopology; /* = LLGLPrimitiveTopologyTriangleList */ + size_t numViewports; /* = 0 */ + const LLGLViewport* viewports; /* = NULL */ + size_t numScissors; /* = 0 */ + const LLGLScissor* scissors; /* = NULL */ LLGLDepthDescriptor depth; LLGLStencilDescriptor stencil; LLGLRasterizerDescriptor rasterizer; @@ -1574,7 +1574,7 @@ LLGLGraphicsPipelineDescriptor; typedef struct LLGLResourceViewDescriptor { - LLGLResource resource; /* = nullptr */ + LLGLResource resource; /* = LLGL_NULL_OBJECT */ LLGLTextureViewDescriptor textureView; LLGLBufferViewDescriptor bufferView; uint32_t initialCount; /* = 0 */ @@ -1583,13 +1583,13 @@ LLGLResourceViewDescriptor; typedef struct LLGLShaderDescriptor { - LLGLShaderType type; /* = ShaderType::Undefined */ - const char* source; /* = nullptr */ + LLGLShaderType type; /* = LLGLShaderTypeUndefined */ + const char* source; /* = NULL */ size_t sourceSize; /* = 0 */ - LLGLShaderSourceType sourceType; /* = ShaderSourceType::CodeFile */ - const char* entryPoint; /* = nullptr */ - const char* profile; /* = nullptr */ - const LLGLShaderMacro* defines; /* = nullptr */ + LLGLShaderSourceType sourceType; /* = LLGLShaderSourceTypeCodeFile */ + const char* entryPoint; /* = NULL */ + const char* profile; /* = NULL */ + const LLGLShaderMacro* defines; /* = NULL */ long flags; /* = 0 */ LLGLVertexShaderAttributes vertex; LLGLFragmentShaderAttributes fragment; @@ -1599,10 +1599,10 @@ LLGLShaderDescriptor; typedef struct LLGLShaderReflection { - size_t numResources; - const LLGLShaderResourceReflection* resources; - size_t numUniforms; - const LLGLUniformDescriptor* uniforms; + size_t numResources; /* = 0 */ + const LLGLShaderResourceReflection* resources; /* = NULL */ + size_t numUniforms; /* = 0 */ + const LLGLUniformDescriptor* uniforms; /* = NULL */ LLGLVertexShaderAttributes vertex; LLGLFragmentShaderAttributes fragment; LLGLComputeShaderAttributes compute; diff --git a/scripts/GenerateWrappers.bat b/scripts/GenerateWrappers.bat index c2ce0cb9b7..8ee01ddcd4 100644 --- a/scripts/GenerateWrappers.bat +++ b/scripts/GenerateWrappers.bat @@ -6,6 +6,7 @@ if not exist .\ParseLLGLHeader.py ( ) set INCLUDE=..\include\LLGL +set CINCLUDE=..\include\LLGL-C set INPUT=^ %INCLUDE%\BufferFlags.h ^ @@ -35,18 +36,46 @@ set INPUT=^ %INCLUDE%\VertexAttribute.h ^ %INCLUDE%\WindowFlags.h +set INPUT_FN=^ + %INPUT% ^ + %CINCLUDE%\Buffer.h ^ + %CINCLUDE%\CommandBuffer.h ^ + %CINCLUDE%\CommandQueue.h ^ + %CINCLUDE%\PipelineLayout.h ^ + %CINCLUDE%\PipelineState.h ^ + %CINCLUDE%\QueryHeap.h ^ + %CINCLUDE%\RenderSystem.h ^ + %CINCLUDE%\RenderTarget.h ^ + %CINCLUDE%\Report.h ^ + %CINCLUDE%\Resource.h ^ + %CINCLUDE%\Shader.h ^ + %CINCLUDE%\Surface.h ^ + %CINCLUDE%\SwapChain.h ^ + %CINCLUDE%\Texture.h ^ + %CINCLUDE%\Timer.h + +REM %CINCLUDE%\Canvas.h ^ +REM %CINCLUDE%\Display.h ^ +REM %CINCLUDE%\Log.h ^ +REM %CINCLUDE%\Window.h ^ + REM Generate wrapper for C99, C# -call :Generate c99 .\LLGLWrapper.h -REM call :Generate csharp .\LLGLWrapper.cs +call :Generate .\LLGLWrapper.h -c99 +call :Generate .\LLGLWrapper.cs -csharp -fn exit /B 0 :Generate -set LANGUAGE=%~1 -set OUTPUT=%~2 +set OUTPUT=%~1 +set LANGUAGE=%~2 +set FUNCTIONS=%~3 REM Generate wrapper -set ARGS=.\ParseLLGLHeader.py -%LANGUAGE% "-name=LLGLWrapper" %INPUT% +if "%FUNCTIONS%"=="" ( + set ARGS=.\ParseLLGLHeader.py "-name=LLGLWrapper" %LANGUAGE% %INPUT% +) else ( + set ARGS=.\ParseLLGLHeader.py "-name=LLGLWrapper" %LANGUAGE% %FUNCTIONS% %INPUT_FN% +) REM Run Python script to parse LLGL headers and write result into output file python3 %ARGS% > %OUTPUT% diff --git a/scripts/ParseLLGLHeader.py b/scripts/ParseLLGLHeader.py index 6e6a81850c..1ad210285c 100644 --- a/scripts/ParseLLGLHeader.py +++ b/scripts/ParseLLGLHeader.py @@ -19,6 +19,7 @@ def printHelp(): print(" -c99 ......... Translate header to C99") print(" -csharp ...... Translate header to C#") print(" -name=NAME ... Override name for consolidated headers") + print(" -fn .......... Also parse exported C function declarations") def iterate(func, cont): return list(map(func, cont)) @@ -61,9 +62,28 @@ def __init__(self, name, cond = None, include = None): class LLGLMeta: UTF8STRING = 'UTF8String' STRING = 'string' - builtins = [ + externals = [ ConditionalType('android_app', 'defined LLGL_OS_ANDROID', '') ] + builtins = { + 'void': StdType.VOID, + 'bool': StdType.BOOL, + 'char': StdType.CHAR, + 'int8_t': StdType.INT8, + 'int16_t': StdType.INT16, + 'short': StdType.INT16, + 'int32_t': StdType.INT32, + 'int': StdType.INT32, + 'int64_t': StdType.INT64, + 'uint8_t': StdType.UINT8, + 'uint16_t': StdType.UINT16, + 'uint32_t': StdType.UINT32, + 'uint64_t': StdType.UINT64, + 'long': StdType.LONG, + 'size_t': StdType.SIZE_T, + 'float': StdType.FLOAT, + 'const': StdType.CONST + } containers = [ 'vector', 'ArrayView' @@ -74,6 +94,7 @@ class LLGLMeta: 'Canvas', 'CommandBuffer', 'CommandQueue', + 'Display', 'Fence', 'Image', 'PipelineLayout', @@ -104,6 +125,8 @@ class LLGLMeta: info = [ 'AUTO GENERATED CODE - DO NOT EDIT' ] + funcPrefix = 'llgl' + typePrefix = 'LLGL' class LLGLMacros: def translateArraySize(ident): @@ -118,7 +141,7 @@ class LLGLType: arraySize = 0 # 0 for non-array, -1 for dynamic array, anything else for fixed size array isConst = False isPointer = False - builtinCond = None # Conditional expression string for builtin typenames (see LLGLMeta.builtins) + externalCond = None # Conditional expression string for external typenames (see LLGLMeta.externals) DYNAMIC_ARRAY = -1 @@ -128,7 +151,7 @@ def __init__(self, typename = '', isConst = False, isPointer = False): self.arraySize = 0 self.isConst = isConst self.isPointer = isPointer - self.builtinCond = next((builtin.cond for builtin in LLGLMeta.builtins if builtin.name == typename), None) + self.externalCond = next((external.cond for external in LLGLMeta.externals if external.name == typename), None) def setArraySize(self, arraySize): if isinstance(arraySize, str): @@ -150,38 +173,8 @@ def __str__(self): def toBaseType(typename): if typename != '': - if typename == 'void': - return StdType.VOID - elif typename == 'bool': - return StdType.BOOL - elif typename == 'char': - return StdType.CHAR - elif typename == 'int8_t': - return StdType.INT8 - elif typename in ['int16_t', 'short']: - return StdType.INT16 - elif typename in ['int32_t', 'int']: - return StdType.INT32 - elif typename == 'int64_t': - return StdType.INT64 - elif typename == 'uint8_t': - return StdType.UINT8 - elif typename == 'uint16_t': - return StdType.UINT16 - elif typename == 'uint32_t': - return StdType.UINT32 - elif typename == 'uint64_t': - return StdType.UINT64 - elif typename == 'long': - return StdType.LONG - elif typename == 'size_t': - return StdType.SIZE_T - elif typename == 'float': - return StdType.FLOAT - elif typename == 'const': - return StdType.CONST - else: - return StdType.STRUCT + builtin = LLGLMeta.builtins.get(typename) + return builtin if builtin else StdType.STRUCT return StdType.UNDEFINED # Returns true if this type is a custom LLGL enum, flags, or struct declaration @@ -214,17 +207,19 @@ class LLGLField: type = LLGLType() init = None - def __init__(self, name): + def __init__(self, name, type = LLGLType()): self.name = name + self.type = type + self.init = None def __str__(self): str = '' if self.type.baseType != StdType.UNDEFINED: - str += '{}:{}'.format(self.name, self.type) + str += f'{self.name}:{self.type}' else: - str += '{}'.format(self.name) - if self.init != None: - str += '({})'.format(self.init) + str += f'{self.name}' + if self.init: + str += f'({self.init})' return str class LLGLRecord: @@ -251,11 +246,22 @@ def deriveDependencies(self): if field.type.isCustomType() and not field.type.isInterface() and field.type.typename != self.name: self.deps.add(field.type.typename) +class LLGLFunction: + returnType = LLGLType() + name = '' + params = [] # Array of LLGLField + + def __init__(self, name, returnType = LLGLType()): + self.returnType = returnType + self.name = name + self.params = [] + class LLGLModule: name = '' - enums = [] - flags = [] - structs = [] + enums = [] # Array of LLGLRecord + flags = [] # Array of LLGLRecord + structs = [] # Array of LLGLRecord + funcs = [] # Array of LLGLFunction typeDeps = set() # Set of types used in this header def __init__(self): @@ -263,6 +269,7 @@ def __init__(self): self.enums = [] self.flags = [] self.structs = [] + self.funcs = [] self.typeDeps = set() def deriveDependencies(self): @@ -274,6 +281,7 @@ def merge(self, other): self.enums.extend(other.enums) self.flags.extend(other.flags) self.structs.extend(other.structs) + self.funcs.extend(other.funcs) self.typeDeps.update(other.typeDeps) def findStructByName(self, name): @@ -288,7 +296,7 @@ def sortStructsByDependencies(self): struct.deriveDependencies() # Start with structs that have no dependencies - knownTypenames = set(builtin.name for builtin in LLGLMeta.builtins) + knownTypenames = set(external.name for external in LLGLMeta.externals) baseTypenames = set(enum.name for enum in self.enums) | set(flag.name for flag in self.flags) | knownTypenames sortedStructs = [] pendingStructs = [] @@ -509,8 +517,9 @@ def parseType(self): else: isConst = self.scanner.acceptIf('const') typename = self.scanner.accept() + isConst = self.scanner.acceptIf('const') or isConst if typename in LLGLMeta.containers and self.scanner.acceptIf('<'): - isConst = self.scanner.acceptIf('const') + isConst = self.scanner.acceptIf('const') or isConst typename = self.scanner.accept() isPointer = self.scanner.acceptIf('*') self.scanner.acceptOrFail('>') @@ -566,15 +575,58 @@ def parseStructMembers(self, structName): self.scanner.acceptOrFail(';') return members + def parseParameter(self): + # Only parse return type name parameter name as C does not support default arguments + paramType = self.parseType() + param = LLGLField(self.scanner.accept(), paramType) + + # Parse optional fixed size array + if self.scanner.acceptIf('['): + param.type.setArraySize(self.scanner.accept()) + self.scanner.acceptOrFail(']') + + self.scanner.acceptIf('LLGL_NULLABLE') + + return param + + def parseFunctionDecl(self): + # Parse return type + returnType = self.parseType() + + # Parse function name + name = self.scanner.accept() + + # Parse parameter list + func = LLGLFunction(name, returnType) + + self.scanner.acceptOrFail('(') + if not self.scanner.match(')'): + if self.scanner.match(['void', ')']): + # Ignore explicit empty parameter list + self.scanner.accept() + else: + # Parse parameters until no more ',' is scanned + while True: + func.params.append(self.parseParameter()) + if not self.scanner.acceptIf(','): + break + self.scanner.acceptOrFail(')') + self.scanner.acceptOrFail(';') + + return func + # Parses input file by filename and returns LLGLModule - def parseHeader(self, filename): + def parseHeader(self, filename, processFunctions = False): mod = LLGLModule() mod.name = os.path.splitext(os.path.basename(filename))[0] self.scanner.scan(filename) while self.scanner.good(): - if self.scanner.acceptIf(['enum', 'class']): + if processFunctions and self.scanner.acceptIf('LLGL_C_EXPORT'): + # Parse function declaration + mod.funcs.append(self.parseFunctionDecl()) + elif self.scanner.acceptIf(['enum', 'class']): # Parse enumeration name = self.scanner.accept() enum = LLGLRecord(name) @@ -607,19 +659,24 @@ def parseHeader(self, filename): return mod -def parseFile(filename): +def parseFile(filename, processFunctions = False): parser = Parser() - mod = parser.parseHeader(filename) + mod = parser.parseHeader(filename, processFunctions) mod.deriveDependencies() return mod def printModule(module): - def printField(field): - print('@FIELD{' + str(field) + '}') + def printField(field, type): + print('@' + type + '{' + str(field) + '}') def printRecord(record, type): print('@' + type + '{' + record.name + '}') - iterate(printField, record.fields) + iterate(lambda field: printField(field, 'FIELD'), record.fields) + print('@END') + + def printFunc(func, type): + print('@' + type + '{' + func.name + '}=>' + str(func.returnType)) + iterate(lambda param: printField(param, 'PARAM'), func.params) print('@END') print('@HEADER{' + module.name + '}') @@ -627,6 +684,7 @@ def printRecord(record, type): iterate(lambda record: printRecord(record, 'ENUM'), module.enums) iterate(lambda record: printRecord(record, 'FLAG'), module.flags) iterate(lambda record: printRecord(record, 'STRUCT'), filter(lambda record: not record.hasConstFieldsOnly(), module.structs)) + iterate(lambda func: printFunc(func, 'FUNC'), module.funcs) print('@END') class Translator: @@ -656,9 +714,9 @@ def __init__(self): def append(self, decl): self.decls.append(decl) if not decl.directive: - self.maxLen[0] = max(self.maxLen[0], len(decl.type)) + self.maxLen[0] = max(self.maxLen[0], len(decl.type) if decl.type else 0) self.maxLen[1] = max(self.maxLen[1], len(decl.name)) - self.maxLen[2] = max(self.maxLen[2], len(decl.init) if decl.init != None else 0) + self.maxLen[2] = max(self.maxLen[2], len(decl.init) if decl.init else 0) def spaces(self, index, str): return ' ' * (self.maxLen[index] - len(str) + 1) @@ -667,7 +725,10 @@ def indentation(self): return ' ' * (self.indent * self.tabSize) def statement(self, line): - print(self.indentation() + line) + if len(line) > 0 and line[0] == '#': + print(line) + else: + print(self.indentation() + line) def openScope(self, stmt = '{'): self.statement(stmt) @@ -697,7 +758,7 @@ def translateIncludes(typeDeps): llglIncludes = LLGLMeta.includes.copy() for dep in typeDeps: inc = translateDependency(dep) - if inc and inc[0] != None: + if inc and inc[0]: if inc[1]: stdIncludes.add(inc[0]) #else: @@ -729,12 +790,12 @@ def translateIncludes(typeDeps): for inc in includeHeaders[i]: self.statement('#include {}'.format(inc)) - for builtin in LLGLMeta.builtins: - if builtin.cond and builtin.include: + for external in LLGLMeta.externals: + if external.cond and external.include: self.statement('') - self.statement(f'#if {builtin.cond}') - self.statement(f'# include {builtin.include}') - self.statement(f'#endif /* {builtin.cond} */') + self.statement(f'#if {external.cond}') + self.statement(f'# include {external.include}') + self.statement(f'#endif /* {external.cond} */') self.statement('') self.statement('') @@ -745,6 +806,7 @@ def translateIncludes(typeDeps): if len(constStructs) > 0: self.statement('/* ----- Constants ----- */') self.statement('') + for struct in constStructs: # Write struct field declarations declList = Translator.DeclarationList() @@ -754,6 +816,7 @@ def translateIncludes(typeDeps): for decl in declList.decls: self.statement('#define ' + decl.name + declList.spaces(1, decl.name) + ' ( ' + decl.init + ' )') self.statement('') + self.statement('') # Write all enumerations @@ -762,6 +825,7 @@ def translateIncludes(typeDeps): if len(doc.enums) > 0: self.statement('/* ----- Enumerations ----- */') self.statement('') + for enum in doc.enums: if enum.base: bitsize = enum.base.getFixedBitsize() @@ -777,7 +841,7 @@ def translateIncludes(typeDeps): declList.append(Translator.Declaration('', 'LLGL{}{}'.format(enum.name, field.name), field.init)) for decl in declList.decls: - if decl.init != None: + if decl.init: self.statement(decl.name + declList.spaces(1, decl.name) + '= ' + decl.init + ',') else: self.statement(decl.name + ',') @@ -785,6 +849,7 @@ def translateIncludes(typeDeps): self.closeScope() self.statement('LLGL{};'.format(enum.name)) self.statement('') + self.statement('') # Write all flags @@ -807,6 +872,7 @@ def translateFieldName(name): self.statement('/* ----- Flags ----- */') self.statement('') + for flag in doc.flags: self.statement('typedef enum LLGL{}'.format(flag.name)) basename = flag.name[:-len('Flags')] @@ -820,7 +886,7 @@ def translateFieldName(name): declList.append(Translator.Declaration('', fieldName, translateFlagInitializer(basename, field.init) if field.init else None)) for decl in declList.decls: - if decl.init != None: + if decl.init: self.statement(decl.name + declList.spaces(1, decl.name) + '= ' + decl.init + ',') else: self.statement(decl.name + ',') @@ -828,6 +894,7 @@ def translateFieldName(name): self.closeScope() self.statement('LLGL{};'.format(flag.name)) self.statement('') + self.statement('') # Write all structures @@ -850,7 +917,7 @@ def translateStructField(type, name): else: if type.isConst: typeStr += 'const ' - if type.baseType == StdType.STRUCT and type.builtinCond == None: + if type.baseType == StdType.STRUCT and not type.externalCond: typeStr += 'LLGL' typeStr += type.typename if type.isPointer: @@ -873,8 +940,19 @@ def translateStructField(type, name): return (typeStr, declStr) + def translateFieldInitializer(type, init): + if type.isDynamicArray(): + return 'NULL' + if init: + if init == 'nullptr': + return 'LLGL_NULL_OBJECT' if type.isInterface() else 'NULL' + else: + return re.sub(r'(\w+::)', r'LLGL\1', init).replace('::', '').replace('|', ' | ').replace('Flags', '') + return None + self.statement('/* ----- Structures ----- */') self.statement('') + for struct in commonStructs: self.statement('typedef struct LLGL{}'.format(struct.name)) self.openScope() @@ -883,15 +961,15 @@ def translateStructField(type, name): declList = Translator.DeclarationList() for field in struct.fields: # Write two fields for dynamic arrays - builtinCond = field.type.builtinCond - if builtinCond: - declList.append(Translator.Declaration(directive = f'#if {builtinCond}')) + externalCond = field.type.externalCond + if externalCond: + declList.append(Translator.Declaration(directive = f'#if {externalCond}')) if field.type.isDynamicArray(): - declList.append(Translator.Declaration('size_t', f'num{field.name[0].upper()}{field.name[1:]}')) + declList.append(Translator.Declaration('size_t', f'num{field.name[0].upper()}{field.name[1:]}', '0')) declStr = translateStructField(field.type, field.name) - declList.append(Translator.Declaration(declStr[0], declStr[1], field.init)) - if builtinCond: - declList.append(Translator.Declaration(directive = f'#endif /* {builtinCond} */')) + declList.append(Translator.Declaration(declStr[0], declStr[1], translateFieldInitializer(field.type, field.init))) + if externalCond: + declList.append(Translator.Declaration(directive = f'#endif /* {externalCond} */')) for decl in declList.decls: if decl.directive: @@ -903,6 +981,7 @@ def translateStructField(type, name): self.closeScope() self.statement('LLGL{};'.format(struct.name)) self.statement('') + self.statement('') self.statement('#endif /* {} */'.format(headerGuardName)) @@ -913,6 +992,23 @@ def translateStructField(type, name): self.statement('') def translateModuleToCsharp(self, doc): + builtinTypenames = { + StdType.VOID: 'void', + StdType.BOOL: 'bool', + StdType.CHAR: 'byte', + StdType.INT8: 'sbyte', + StdType.INT16: 'short', + StdType.INT32: 'int', + StdType.INT64: 'long', + StdType.UINT8: 'byte', + StdType.UINT16: 'ushort', + StdType.UINT32: 'uint', + StdType.UINT64: 'ulong', + StdType.LONG: 'long', + StdType.SIZE_T: 'UIntPtr', + StdType.FLOAT: 'float' + } + self.statement('/*') self.statement(' * {}.cs'.format(doc.name)) self.statement(' *') @@ -926,8 +1022,18 @@ def translateModuleToCsharp(self, doc): self.statement('using System;') self.statement('using System.Runtime.InteropServices;') self.statement('') - self.statement('namespace LLGL') + self.statement('namespace LLGLModule') self.openScope() + self.statement('public static partial class LLGL') + self.openScope() + + # Write DLL name + self.statement('#if DEBUG') + self.statement('const string DllName = "LLGLD.dll";') + self.statement('#else') + self.statement('const string DllName = "LLGL.dll";') + self.statement('#endif') + self.statement('') # Write all constants constStructs = list(filter(lambda record: record.hasConstFieldsOnly(), doc.structs)) @@ -935,6 +1041,7 @@ def translateModuleToCsharp(self, doc): if len(constStructs) > 0: self.statement('/* ----- Constants ----- */') self.statement('') + for struct in constStructs: self.statement('public enum {} : int'.format(struct.name)) self.openScope() @@ -949,12 +1056,27 @@ def translateModuleToCsharp(self, doc): self.closeScope() self.statement('') + self.statement('') + # Write all interface handles + self.statement('/* ----- Handles ----- */') + self.statement('') + + for interface in LLGLMeta.interfaces: + self.statement(f'public unsafe struct {interface}') + self.openScope() + self.statement('internal unsafe void* ptr;') + self.closeScope() + self.statement('') + + self.statement('') + # Write all enumerations if len(doc.enums) > 0: self.statement('/* ----- Enumerations ----- */') self.statement('') + for enum in doc.enums: self.statement('public enum ' + enum.name) self.openScope() @@ -965,13 +1087,14 @@ def translateModuleToCsharp(self, doc): declList.append(Translator.Declaration('', field.name, field.init)) for decl in declList.decls: - if decl.init != None: + if decl.init: self.statement(decl.name + declList.spaces(1, decl.name) + '= ' + decl.init + ',') else: self.statement(decl.name + ',') self.closeScope() self.statement('') + self.statement('') # Write all flags @@ -983,6 +1106,7 @@ def translateFlagInitializer(init): self.statement('/* ----- Flags ----- */') self.statement('') + for flag in doc.flags: self.statement('[Flags]') self.statement('public enum {} : uint'.format(flag.name)) @@ -995,69 +1119,69 @@ def translateFlagInitializer(init): declList.append(Translator.Declaration('', field.name, translateFlagInitializer(field.init) if field.init else None)) for decl in declList.decls: - if decl.init != None: + if decl.init: self.statement(decl.name + declList.spaces(1, decl.name) + '= ' + decl.init + ',') else: self.statement(decl.name + ',') self.closeScope() self.statement('') + self.statement('') # Write all structures commonStructs = list(filter(lambda record: not record.hasConstFieldsOnly(), doc.structs)) - if len(commonStructs) > 0: - def translateStructField(type, name): - def translateType(type): - if type.baseType == StdType.VOID: - return 'void' - elif type.baseType == StdType.BOOL: - return 'bool' - elif type.baseType == StdType.CHAR: - return 'byte' - elif type.baseType == StdType.INT8: - return 'sbyte' - elif type.baseType == StdType.INT16: - return 'short' - elif type.baseType == StdType.INT32: - return 'int' - elif type.baseType == StdType.INT64: - return 'long' - elif type.baseType == StdType.UINT8: - return 'byte' - elif type.baseType == StdType.UINT16: - return 'ushort' - elif type.baseType == StdType.UINT32: - return 'uint' - elif type.baseType == StdType.UINT64: - return 'ulong' - elif type.baseType == StdType.LONG: - return 'long' - elif type.baseType == StdType.SIZE_T: - return 'UIntPtr' - elif type.baseType == StdType.FLOAT: - return 'float' - else: - return type.typename + class CsharpDeclaration: + marshal = None + type = '' + ident = '' - typeStr = '' - declStr = '' - if type.baseType == StdType.STRUCT and type.typename in LLGLMeta.interfaces: - typeStr += type.typename + def __init__(self, ident): + self.marshal = None + self.type = '' + self.ident = ident + + def translateDecl(type, ident = None, isInsideStruct = False): + decl = CsharpDeclaration(ident) + + def sanitizeTypename(typename): + if typename.startswith(LLGLMeta.typePrefix): + return typename[len(LLGLMeta.typePrefix):] + elif typename in [LLGLMeta.UTF8STRING, LLGLMeta.STRING]: + return 'string' else: - if type.arraySize > 0: - typeStr += 'fixed ' - typeStr += translateType(type) + return typename + + nonlocal builtinTypenames + + if type.baseType == StdType.STRUCT and type.typename in LLGLMeta.interfaces: + decl.type = sanitizeTypename(type.typename) + else: + builtin = builtinTypenames.get(type.baseType) + if isInsideStruct: + if type.arraySize > 0 and builtin: + decl.type += 'fixed ' + decl.type += builtin if builtin else sanitizeTypename(type.typename) if type.isPointer: - typeStr += '*' - declStr += name - if type.arraySize > 0: - declStr += '[{}]'.format(type.arraySize) - return (typeStr, declStr) + decl.type += '*' + elif type.arraySize > 0: + if builtin: + decl.ident += f'[{type.arraySize}]' + else: + decl.marshal = f'MarshalAs(UnmanagedType.ByValArray, SizeConst = {type.arraySize})' + decl.type += '[]' + else: + decl.type += builtin if builtin else sanitizeTypename(type.typename) + if type.isPointer or type.arraySize > 0: + decl.type += '*' + + return decl + if len(commonStructs) > 0: self.statement('/* ----- Structures ----- */') self.statement('') + for struct in commonStructs: self.statement('public unsafe struct ' + struct.name) self.openScope() @@ -1065,21 +1189,48 @@ def translateType(type): # Write struct field declarations declList = Translator.DeclarationList() for field in struct.fields: - # Write two fields for dynamic arrays - if field.type.arraySize == -1: - declList.append(Translator.Declaration('UIntPtr', 'num{}{}'.format(field.name[0].upper(), field.name[1:]))) - declStr = translateStructField(field.type, field.name) - declList.append(Translator.Declaration(declStr[0], declStr[1], field.init)) + if not field.type.externalCond: + # Write two fields for dynamic arrays + if field.type.arraySize == -1: + declList.append(Translator.Declaration('UIntPtr', 'num{}{}'.format(field.name[0].upper(), field.name[1:]))) + fieldDecl = translateDecl(field.type, field.name, isInsideStruct = True) + if fieldDecl.marshal: + declList.append(Translator.Declaration(None, fieldDecl.marshal)) + declList.append(Translator.Declaration(fieldDecl.type, fieldDecl.ident, field.init)) for decl in declList.decls: - if decl.init != None: - self.statement('public ' + decl.type + declList.spaces(0, decl.type) + decl.name + ';' + declList.spaces(1, decl.name) + '/* = ' + decl.init + ' */') + if not decl.type: + self.statement(f'[{decl.name}]') + elif decl.init: + self.statement(f'public {decl.type}{declList.spaces(0, decl.type)}{decl.name};{declList.spaces(1, decl.name)}/* = {decl.init} */') else: - self.statement('public ' + decl.type + declList.spaces(0, decl.type) + decl.name + ';') + self.statement(f'public {decl.type}{declList.spaces(0, decl.type)}{decl.name};') self.closeScope() self.statement('') + + self.statement('') + + # Write all functions + if len(doc.funcs) > 0: + self.statement('/* ----- Functions ----- */') + self.statement('') + + for func in doc.funcs: + self.statement(f'[DllImport(DllName, EntryPoint="{func.name}", CallingConvention=CallingConvention.Cdecl)]'); + returnTypeStr = translateDecl(func.returnType).type + paramListStr = '' + for param in func.params: + if len(paramListStr) > 0: + paramListStr += ', ' + paramDecl = translateDecl(param.type, param.name) + paramListStr += f'{paramDecl.type} {paramDecl.ident}' + funcName = func.name[len(LLGLMeta.funcPrefix):] + self.statement(f'public static extern unsafe {returnTypeStr} {funcName}({paramListStr});'); + self.statement('') + self.statement('') + self.closeScope() self.closeScope() self.statement('') self.statement('') @@ -1103,10 +1254,13 @@ def findArgValue(args, search): return None singleName = findArgValue(args, '-name') + + # Are function declarations includes? + processFunctions = '-fn' in args # Parse input headers - modules = iterate(parseFile, files) - if singleName != None and len(modules) > 0: + modules = iterate(lambda filename: parseFile(filename, processFunctions), files) + if singleName and len(modules) > 0: singleModule = modules[0] singleModule.name = singleName if len(modules) > 1: