Skip to content

Commit 6e4dfb2

Browse files
committed
Extract field comments
1 parent 0b0c2b3 commit 6e4dfb2

File tree

6 files changed

+5811
-17
lines changed

6 files changed

+5811
-17
lines changed

enums.gen.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,8 +2475,8 @@ const (
24752475
AVChanAmbisonicBase AVChannel = C.AV_CHAN_AMBISONIC_BASE
24762476
// AVChanAmbisonicEnd wraps AV_CHAN_AMBISONIC_END.
24772477
/*
2478-
// leave space for 1024 ids, which correspond to maximum order-32 harmonics,
2479-
// which should be enough for the foreseeable use cases
2478+
leave space for 1024 ids, which correspond to maximum order-32 harmonics,
2479+
which should be enough for the foreseeable use cases
24802480
*/
24812481
AVChanAmbisonicEnd AVChannel = C.AV_CHAN_AMBISONIC_END
24822482
)
@@ -3109,16 +3109,16 @@ const (
31093109
31103110
@code{.c}
31113111
av_rescale_rnd(3, 1, 2, AV_ROUND_UP | AV_ROUND_PASS_MINMAX);
3112-
// Rescaling 3:
3113-
// Calculating 3 * 1 / 2
3114-
// 3 / 2 is rounded up to 2
3115-
// => 2
3112+
Rescaling 3:
3113+
Calculating 3 * 1 / 2
3114+
3 / 2 is rounded up to 2
3115+
=> 2
31163116
31173117
av_rescale_rnd(AV_NOPTS_VALUE, 1, 2, AV_ROUND_UP | AV_ROUND_PASS_MINMAX);
3118-
// Rescaling AV_NOPTS_VALUE:
3119-
// AV_NOPTS_VALUE == INT64_MIN
3120-
// AV_NOPTS_VALUE is passed through
3121-
// => AV_NOPTS_VALUE
3118+
Rescaling AV_NOPTS_VALUE:
3119+
AV_NOPTS_VALUE == INT64_MIN
3120+
AV_NOPTS_VALUE is passed through
3121+
=> AV_NOPTS_VALUE
31223122
@endcode
31233123
*/
31243124
AVRoundPassMinmax AVRounding = C.AV_ROUND_PASS_MINMAX
@@ -3565,7 +3565,7 @@ const (
35653565
AVPixFmtGbrp AVPixelFormat = C.AV_PIX_FMT_GBRP
35663566
// AVPixFmtGbr24P wraps AV_PIX_FMT_GBR24P.
35673567
//
3568-
// // alias for #AV_PIX_FMT_GBRP
3568+
// alias for #AV_PIX_FMT_GBRP
35693569
AVPixFmtGbr24P AVPixelFormat = C.AV_PIX_FMT_GBR24P
35703570
// AVPixFmtGbrp9Be wraps AV_PIX_FMT_GBRP9BE.
35713571
//

functions.gen.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9669,14 +9669,14 @@ func AVFree(ptr unsafe.Pointer) {
96699669
@code{.c}
96709670
uint8_t *buf = av_malloc(16);
96719671
av_free(buf);
9672-
// buf now contains a dangling pointer to freed memory, and accidental
9673-
// dereference of buf will result in a use-after-free, which may be a
9674-
// security risk.
9672+
buf now contains a dangling pointer to freed memory, and accidental
9673+
dereference of buf will result in a use-after-free, which may be a
9674+
security risk.
96759675
96769676
uint8_t *buf = av_malloc(16);
96779677
av_freep(&buf);
9678-
// buf is now NULL, and accidental dereference will only result in a
9679-
// NULL-pointer dereference.
9678+
buf is now NULL, and accidental dereference will only result in a
9679+
NULL-pointer dereference.
96809680
@endcode
96819681
96829682
@param ptr Pointer to the pointer to the memory block which should be freed

internal/generator/file.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Field struct {
5353
Name string
5454
Type Type
5555
BitWidth int32
56+
Comment string
5657
}
5758

5859
type Enum struct {

internal/generator/generator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ func (g *Generator) generateStructs() {
646646
}
647647

648648
o.Commentf("%v gets the %v field.", fName, field.Name)
649+
650+
if field.Comment != "" {
651+
o.Comment(field.Comment)
652+
}
653+
649654
o.Func().
650655
Params(jen.Id("s").Op("*").Id(goName)).
651656
Id(fName).
@@ -657,6 +662,11 @@ func (g *Generator) generateStructs() {
657662

658663
if len(setBody) > 0 {
659664
o.Commentf("Set%v sets the %v field.", fName, field.Name)
665+
666+
if field.Comment != "" {
667+
o.Comment(field.Comment)
668+
}
669+
660670
o.Func().
661671
Params(jen.Id("s").Op("*").Id(goName)).
662672
Id(fmt.Sprintf("Set%v", fName)).

internal/generator/parser.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ func processComment(in string) string {
292292
s = strings.TrimPrefix(s, "* ")
293293
s = strings.TrimPrefix(s, "/// ")
294294
s = strings.TrimPrefix(s, "///")
295+
s = strings.TrimPrefix(s, "// ")
296+
s = strings.TrimPrefix(s, "//")
295297

296298
if strings.HasPrefix(s, "/**") {
297299
rebuilt = nil
@@ -501,6 +503,8 @@ func (p *Parser) parseStruct(indent string, c clang.Cursor, typedef bool) {
501503
log.Fatal("no field name")
502504
}
503505

506+
cmt := processComment(cursor.RawCommentText())
507+
504508
fIndent := fmt.Sprintf("%v[%v]", indent, name)
505509

506510
ty := p.parseType(fIndent, cursor.Type())
@@ -509,6 +513,7 @@ func (p *Parser) parseStruct(indent string, c clang.Cursor, typedef bool) {
509513
Name: name,
510514
Type: ty,
511515
BitWidth: cursor.FieldDeclBitWidth(),
516+
Comment: cmt,
512517
})
513518
}
514519

0 commit comments

Comments
 (0)