Skip to content

Add struct init parser for AV_CHANNEL_LAYOUT and AV_TIME_BASE_Q#347

Open
Ruslan-B wants to merge 3 commits intomainfrom
feature/struct-init-parser
Open

Add struct init parser for AV_CHANNEL_LAYOUT and AV_TIME_BASE_Q#347
Ruslan-B wants to merge 3 commits intomainfrom
feature/struct-init-parser

Conversation

@Ruslan-B
Copy link
Owner

Summary

  • Parser: C99 compound literals (Type){...}, designated initializers { .field = expr }, nested fields (.u.mask), NULL handling
  • Tokenizer: .field lookahead to distinguish designated init from number literals
  • MacroPostProcessor: function macro expansion with { body, /* .field */.field = comment conversion, struct type inference from field names, enum field serialization via member lookup
  • 42 AV_CHANNEL_LAYOUT_* macros now generate as static readonly AVChannelLayout
  • AV_TIME_BASE_Q generates as static readonly AVRational
  • Remove orphaned MediaDecoder.cs (unused duplicate of VideoFrameConverter with memory leak)

Closes #258

Test plan

  • 28 parser unit tests pass
  • Solution builds with 0 errors, 0 warnings
  • Example decode verified — 121+ frames extracted successfully

🤖 Generated with Claude Code

Ruslan-B and others added 3 commits March 18, 2026 23:30
Parser:
- InitializerListExpression: { expr, expr } and { .field = expr }
- CompoundLiteralExpression: (Type){ expr, expr }
- C comment skipping (/* ... */) in expressions
- NULL literal handling
- TryToOperationType (replaces try/catch in MaybeBinary)
- IsTypeInParentheses (shared by IsCast and IsCompoundLiteral)

MacroPostProcessor:
- DeduceType, Rewrite, Serialize, IsConst for new expression types
- Positional field name resolution from struct definitions
- IsValid check for compound literals with known struct types

Result: AV_TIME_BASE_Q now generates as:
  new AVRational { num = 0x1, den = AV_TIME_BASE }

Tests: 5 new (27 total) — compound literal, initializer list,
designated init, C comments, NULL

Next: type inference for AV_CHANNEL_LAYOUT_MASK (+42 macros)
- TryExpandFunctionMacro: use \b word-boundary regex for parameter substitution
  (fixes corruption when short params like 'm' appear inside other words)
- DeduceStructType: infer struct type from designated initializer field names
  by matching against known struct definitions
- Convert C-style designated init comments to actual designators:
  { /* .field */ value } → { .field = value }
- IsValid: support struct-typed InitializerList expressions

Channel layout macros (AV_CHANNEL_LAYOUT_*) parse and expand correctly
but require struct-aware serialization (enum casts, nested union init,
void* handling) — deferred to next iteration.
- Parser: compound literals (Type){...}, initializer lists {.field = expr},
  nested designated fields (.u.mask), NULL handling
- Tokenizer: .field lookahead to distinguish designated init from numbers
- MacroPostProcessor: function macro expansion with { body, /* .field */ → .field =
  conversion, struct type inference, enum field serialization via member lookup
- 42 AV_CHANNEL_LAYOUT_* macros now generate as static readonly AVChannelLayout
- AV_TIME_BASE_Q generates as static readonly AVRational
- Remove orphaned MediaDecoder.cs (unused duplicate of VideoFrameConverter)
- 28 parser tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

channel_layout.h missing new (non-deprecated)

1 participant