Skip to content

Commit f3842e4

Browse files
committed
feat(parser): add support for union declarations in typedef parsing
- Implement handling for Union declarations in the parser - Add detailed comments explaining CGO limitations with union types - Prevent panics when encountering union declarations while parsing - Clarify that union fields are treated as opaque types in CGO
1 parent 06a8ba7 commit f3842e4

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

internal/generator/parser.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var files = []string{
8989
"libavutil/iamf.h",
9090
"libavutil/imgutils.h",
9191
"libavutil/intfloat.h",
92-
////"libavutil/intreadwrite.h", //Unknown typedef kind UnionDecl
92+
////"libavutil/intreadwrite.h", //Union types - CGO doesn't expose union fields
9393
"libavutil/lfg.h",
9494
"libavutil/log.h",
9595
"libavutil/lzo.h",
@@ -373,6 +373,14 @@ func (p *Parser) parseTypedef(indent string, c clang.Cursor) {
373373
case clang.Cursor_StructDecl:
374374
p.parseStruct(indent, dec, true)
375375

376+
case clang.Cursor_UnionDecl:
377+
// Unions are similar to structs but all fields share the same memory location.
378+
// NOTE: CGO does not expose union fields directly - unions are treated as opaque types.
379+
// Field accessor generation will fail at compile time. Headers with only union-based
380+
// utilities (like intreadwrite.h) should remain excluded from the files list.
381+
// We parse the structure anyway to avoid panics and for potential future use.
382+
p.parseStruct(indent, dec, true)
383+
376384
case clang.Cursor_EnumDecl:
377385
p.parseEnum(indent, dec, true)
378386

0 commit comments

Comments
 (0)