Add struct init parser for AV_CHANNEL_LAYOUT and AV_TIME_BASE_Q#347
Open
Add struct init parser for AV_CHANNEL_LAYOUT and AV_TIME_BASE_Q#347
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
(Type){...}, designated initializers{ .field = expr }, nested fields (.u.mask), NULL handling.fieldlookahead to distinguish designated init from number literals{body,/* .field */→.field =comment conversion, struct type inference from field names, enum field serialization via member lookupAV_CHANNEL_LAYOUT_*macros now generate asstatic readonly AVChannelLayoutAV_TIME_BASE_Qgenerates asstatic readonly AVRationalMediaDecoder.cs(unused duplicate of VideoFrameConverter with memory leak)Closes #258
Test plan
🤖 Generated with Claude Code