Backlog/lib/sdl3/parser/API_COVERAGE.md

7.4 KiB

SDL3 Parser - API Coverage Analysis

Test Date: 2026-01-22
Headers Tested: 43 major SDL3 APIs
Success Rate: 35% fully working, 65% partial (1-13 errors)


FULLY WORKING APIs (15/43 - 35%)

These APIs generate 100% valid Zig code with zero compilation errors:

API Lines Description
SDL_keyboard.h 301 Keyboard input, scancodes, keycodes
SDL_scancode.h 184 USB keyboard scancodes (300+ values)
SDL_mouse.h 118 Mouse input, buttons, cursor
SDL_rect.h 87 Rectangles, points, float rects
SDL_cpuinfo.h 73 CPU detection, SIMD support
SDL_sensor.h 65 Accelerometer, gyroscope
SDL_time.h 55 Date/time handling
SDL_process.h 45 Process creation
SDL_touch.h 32 Touch input, fingers
SDL_blendmode.h 18 Blend modes for rendering
SDL_pen.h 17 Pen/stylus input
SDL_locale.h 10 System locale detection
SDL_version.h 9 SDL version info
SDL_power.h 7 Battery status
SDL_keycode.h 5 Virtual keycodes

Total: 1,226 lines of perfect Zig code!


⚠️ PARTIAL (Minor Issues - 28/43 - 65%)

🟡 Single Error (Very Close!) - 20 APIs

Just 1 syntax error each - typically function pointers or field name issues:

API Error Type Impact
SDL_audio.h Double pointer spacing Uint8 **Uint8 * *
SDL_camera.h Callback typedef CameraDevice missing
SDL_clipboard.h Callback typedef ClipboardDataCallback
SDL_error.h Function pointer Error callback
SDL_events.h Multi-line comment JoyHat struct
SDL_filesystem.h Callback typedef EnumerateDirectoryCallback
SDL_gamepad.h Field name type shadows primitive
SDL_gpu.h Field name type shadows primitive
SDL_guid.h Array syntax Fixed-size array
SDL_haptic.h Effect union Complex union
SDL_hidapi.h Callback typedef HID device callback
SDL_init.h Callback typedef App lifecycle callbacks
SDL_iostream.h Callback typedef I/O callbacks
SDL_joystick.h Field name type
SDL_log.h Callback typedef LogOutputFunction
SDL_messagebox.h Callback typedef MessageBoxColorType
SDL_mutex.h Function pointer TLS destructor
SDL_pixels.h Callback enum PixelType vs PixelFormat
SDL_render.h Callback typedef RenderVSync
SDL_storage.h Callback typedef Storage callbacks
SDL_surface.h Callback typedef blit map callback
SDL_thread.h Callback typedef ThreadFunction
SDL_tray.h Callback typedef TrayCallback

🟠 Two Errors - 5 APIs

API Issues
SDL_hints.h 2 errors - HintCallback + hint priority enum
SDL_properties.h 2 errors - CleanupPropertyCallback + enum
SDL_timer.h 2 errors - TimerCallback + NSTimerCallback

🟠 Multiple Errors - 2 APIs

API Issues
SDL_dialog.h 4 errors - DialogFileCallback variants
SDL_video.h 13 errors - Multiple function pointer types (HitTest, GLContext, EGLDisplay, etc.)

🔍 Issue Breakdown

Issue #1: Function Pointer Typedefs (50% of errors)

Pattern: typedef void (*CallbackType)(args);

Problem: Parser doesn't handle function pointer typedefs

Affected APIs: 23 out of 28 partial APIs

Examples:

typedef void (*SDL_TimerCallback)(void *userdata, SDL_TimerID timerid, Uint32 interval);
typedef SDL_HitTestResult (*SDL_HitTest)(SDL_Window *win, const SDL_Point *area, void *data);
typedef void (*SDL_LogOutputFunction)(void *userdata, int category, SDL_LogPriority priority, const char *message);

Impact: Functions using these callbacks show as undefined

Priority: HIGH - Would unlock 23 more APIs!


Issue #2: Field Names Shadowing Keywords (10% of errors)

Pattern: Field named type in structs

Affected: SDL_gpu.h, SDL_gamepad.h, SDL_joystick.h

Example:

pub const GPUTexture = extern struct {
    type: GPUTextureType,  // ❌ 'type' is a Zig keyword!
    // Should be: @"type": GPUTextureType
};

Solution: Auto-escape with @"fieldname" for keywords

Priority: MEDIUM - Easy fix, affects 3 APIs


Issue #3: Double Pointer Spacing (5% of errors)

Pattern: Type **param parsed as Type * *param

Affected: SDL_audio.h

Example:

bool SDL_LoadWAV_IO(SDL_IOStream *src, bool closeio, SDL_AudioSpec *spec, 
                    Uint8 **audio_buf, Uint32 *audio_len);

Parsed as: audio_buf: Uint8 * *
Should be: audio_buf: **Uint8 or [*c]*u8

Priority: LOW - Rare pattern


Issue #4: Multi-line Inline Comments (5% of errors)

Pattern: /**< comments spanning multiple lines

Affected: SDL_events.h

Example:

Uint8 value;  /**< The hat position value.
               *   \sa SDL_HAT_LEFTUP
               *   Note that zero means centered.
               */

Status: Known edge case in struct parsing

Priority: LOW - Rare pattern


Issue #5: Complex Unions (5% of errors)

Pattern: Large discriminated unions

Affected: SDL_haptic.h

Priority: LOW - Complex, manual handling may be needed


📊 Statistics

By Category

Category Success Partial Failed
Input 5/7 (71%) 2/7 0
Video/Graphics 2/7 (29%) 5/7 0
Audio 0/1 (0%) 1/1 0
Core/Util 7/12 (58%) 5/12 0
System 1/5 (20%) 4/5 0

Input APIs (Best Category!)

  • keyboard, scancode, mouse, touch, pen
  • ⚠️ gamepad, joystick (field name issues)

Video/Graphics

  • rect, blendmode
  • ⚠️ video (13 errors), render, pixels, surface, gpu (1 each)

Core/Utility

  • cpuinfo, locale, version, power, process, time
  • ⚠️ error, log, properties, hints, timer

🎯 Quick Wins (1-2 hours each)

Win #1: Auto-Escape Keywords

Effort: 1 hour
Impact: Fixes 3 APIs (gpu, gamepad, joystick)

Add to codegen:

const keywords = .{"type", "error", "return", "const", ...};
if (std.mem.indexOfScalar([]const u8, &keywords, field_name)) {
    // Escape it
    try writer.print("@\"{s}\": ", .{field_name});
}

Win #2: Double Pointer Handling

Effort: 1 hour
Impact: Fixes 1 API (audio)

In types.zig:

// Handle "Type **" pattern
if (std.mem.indexOf(u8, trimmed, " **")) |pos| {
    const base = trimmed[0..pos];
    return std.fmt.allocPrint(allocator, "**{s}", .{convertType(base)});
}

Win #3: Function Pointer Basic Support

Effort: 2-3 hours
Impact: Fixes 23 APIs!

Add pattern matching for:

typedef RetType (*Name)(Args);

Generate as:

pub const Name = *const fn(Args) callconv(.C) RetType;

🚀 Impact Summary

Current State:

  • 15/43 APIs fully working (35%)
  • 1,226 lines of perfect code generated

After Quick Wins:

  • 39/43 APIs fully working (91%!)
  • ~3,500 lines estimated

Effort: 4-5 hours total


  1. Function Pointer Typedefs (HIGH) - 2-3 hours, unlocks 23 APIs
  2. Keyword Escaping (MEDIUM) - 1 hour, fixes 3 APIs
  3. Double Pointer Spacing (LOW) - 1 hour, fixes 1 API
  4. Multi-line Comments (LOW) - Already mostly working

Total: ~5 hours to reach 90%+ coverage!