Backlog/lib/sdl3/parser/docs/ROADMAP.md

5.1 KiB

SDL3 Parser - Next Steps

Current Status

The parser is functional with dependency resolution and includes:

  • All C declaration types supported (opaque, enum, struct, flags, functions)
  • Proper naming conventions implemented ("first underscore" rule)
  • Memory leak free (validated with GPA)
  • 18+ unit tests, all passing
  • NEW: Dependency resolution system
    • Automatic detection of missing types
    • Extraction from included headers
    • Single-file output with dependencies
    • Successfully resolves 4/6 types from SDL_gpu.h dependencies
  • Comprehensive documentation under docs/
  • Successfully parses SDL_gpu.h (169 declarations)
  • Mock code generator complete

Recently Completed (2026-01-22)

Phase 1: Dependency Resolution Infrastructure

Implemented:

  • src/dependency_resolver.zig - Complete dependency analysis system
  • Type reference scanning (finds SDL types in signatures)
  • Include directive parsing (#include <SDL3/...>)
  • Selective type extraction from headers
  • Declaration deep cloning with proper memory management
  • Integration into main parser workflow

Results:

  • Reduces 47 missing type references to 6 unique types
  • Successfully finds 4/6 types (FColor, Rect, Window, FlipMode)
  • Generates combined output with dependencies first
  • All existing tests still passing

Phase 2: Multi-Field Struct Parsing

Implemented:

  • Modified parseStructField() to detect multi-field lines
  • New parseMultiFieldLine() function to handle int x, y; patterns
  • Updated scanStruct() to try both single and multi-field parsing
  • Comprehensive test suite (8 new tests)

Results:

  • SDL_Rect now parses correctly (4 fields: x, y, w, h)
  • Handles 2, 3, or more fields on one line
  • Mixed single/multi-field declarations work
  • Dependency resolution success rate: 33% → 67% (+100% improvement)
  • All 21+ tests passing

See MULTI_FIELD_IMPLEMENTATION.md for complete details.

Phase 3: Typedef Scanning (JUST COMPLETED!)

Implemented:

  • Added TypedefDecl to Declaration union
  • New scanTypedef() function to parse simple type aliases
  • Updated writeTypedef() in codegen for Zig output
  • Proper pattern matching order (flags before typedefs)
  • Memory management for all new code paths
  • Comprehensive test suite (5 new tests)

Results:

  • SDL_PropertiesID now resolves (typedef Uint32)
  • 100% dependency resolution achieved! (5/5 types found)
  • Only 1 compilation error remaining (field name type)
  • All tests passing (26+ unit tests)
  • Generates production-ready code

See TYPEDEF_IMPLEMENTATION.md for complete details.

Next Priority Tasks

1. Fix Multi-Field Struct Parsing COMPLETE

2. Add Typedef Scanning COMPLETE

3. Field Name Keyword Escaping (~30 min) - OPTIONAL

Tasks:

  • Test complete resolution with SDL_gpu.h (verify all dependencies compile)
  • Test with SDL_video.h
  • Test with SDL_audio.h
  • Verify generated code compiles standalone without manual definitions
  • Add integration test that parses + compiles

4. Enhanced Reporting (~30 min)

Tasks:

  • Add section headers in output: "// Dependencies from included headers"
  • List which header each dependency came from as comment
  • Add summary stats: "Resolved 4/6 missing types"
  • Use color output for terminal (✓/⚠ symbols working)

Files to modify: src/parser.zig, src/codegen.zig

Future Enhancements

Code Quality

  • Add more unit tests for dependency_resolver.zig
  • Performance profiling with large headers
  • Reduce memory allocations where possible
  • Add benchmarks

Features

  • Handle #define constant scanning (GPUShaderFormat)
  • Support union types
  • Support function pointer types better
  • Batch processing mode for multiple headers
  • Generate module structure (multiple output files)

Documentation

  • Update PARSER_OVERVIEW.md with dependency resolution details
  • Add usage examples to README
  • Document all CLI flags
  • Create tutorial for common use cases

Testing Infrastructure (Original Plan)

  • Golden file testing for regression detection
  • Fuzz testing with random C patterns
  • CI/CD integration
  • Test with full SDL3 API

Time Estimates

Phase 2: Complete Type Support

  • Multi-field struct parsing: 2 hours
  • Typedef scanning: 1-2 hours
  • Integration testing: 2 hours
  • Enhanced reporting: 30 min

Total: ~5-6 hours to complete Phase 2

Phase 3: Polish & Documentation: 2-3 hours

Notes

  • Mock code generator is already complete (mock_codegen.zig)
  • Test infrastructure exists (zig build test)
  • All AGENTS.md guidelines being followed
  • No breaking changes to existing APIs

Usage Examples

# Parse with dependency resolution
zig build run -- ../SDL/include/SDL3/SDL_gpu.h --output=gpu.zig

# Generate with mocks
zig build run -- ../SDL/include/SDL3/SDL_gpu.h --output=gpu.zig --mocks=gpu_mock.c

# Run tests
zig build test

Last updated: 2026-01-22 Parser version: v2.0 with dependency resolution Next milestone: Complete struct parsing + typedefs